Jump to content

Dragging text from listbox onto another app, pasting and pressing enter


Jdop
 Share

Recommended Posts

Title pretty much says it. I want to drag the text from a listview , and paste it onto an external app.

What would be the basic mechanism for this, I've seen some fairly dense code that does many things and only want this basic functionality.

Edited by Jdop
Link to comment
Share on other sites

Title pretty much says it. I want to drag the text from a listview , and paste it onto an external app.

What would be the basic mechanism for this, I've seen some fairly dense code that does many things and only want this basic functionality.

Here is an example of one way to do it.

#include <GUIConstants.au3>

#include <guilistview.au3>


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Choices Dialog", 353, 256, 303, 219)
GUISetIcon("D:07.ico")
$Edit1 = GUICtrlCreateEdit("", 160, 32, 185, 89)
GUICtrlSetData(-1, "Edit1")
$LV = GUICtrlCreateListView("title", 8, 24, 130, 150)
GUICtrlSendMsg(-1, 0x101E, 0, 100)
$ListView1_0 = GUICtrlCreateListViewItem("aaaaaaaaaa", $LV)
$ListView1_1 = GUICtrlCreateListViewItem("bbbbbbbbbbbb", $LV)
$ListView1_2 = GUICtrlCreateListViewItem("cccccccccccc", $LV)
$ListView1_3 = GUICtrlCreateListViewItem("dddddddddd", $LV)
$ListView1_4 = GUICtrlCreateListViewItem("eeeeeeeeeeeeee", $LV)
$ListView1_5 = GUICtrlCreateListViewItem("ffffffffffffff", $LV)
$ListView1_6 = GUICtrlCreateListViewItem("gggggggggggggg", $LV)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$text = ""
$Dragging = False
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            ;get info on control the mouse is over
            $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
            If $Info[4] = $LV Then ;if over the Listview
                gettext()             ;get the text of the selected item
                $dragging = True ;and assume we are dragging
            Else                            ;not over the listview
                $Dragging = False
                $text = ''
            EndIf
            
        Case $GUI_EVENT_PRIMARYUP
                        If $dragging And $text <> ""  Then
              $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
              If $Info[4] <> $LV    Then                
                    MouseClick("LEFT")
                    Send($text & "{ENTER}")
              EndIf
            EndIf
            $dragging = False
            $text = ''
            
    EndSwitch
WEnd


Func gettext()
    
    Local $itemIndex = _GUICtrlListViewGetCurSel ($LV)
    $text = _GUICtrlListViewGetItemText($LV, $itemIndex,0)
    
EndFunc
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Wow, nice solution martin :whistle: ...

This is how it would be much faster and safer (if the text is contain not latinic symbols):

#include <GUIConstants.au3>
#include <guilistview.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Choices Dialog", 353, 256, 303, 219)
GUISetIcon("D:07.ico")
$Edit1 = GUICtrlCreateEdit("", 160, 32, 185, 89)
GUICtrlSetData(-1, "Edit1")
$LV = GUICtrlCreateListView("title", 8, 24, 130, 150)
GUICtrlSendMsg(-1, 0x101E, 0, 100)
$ListView1_0 = GUICtrlCreateListViewItem("текст кириллицы", $LV)
$ListView1_1 = GUICtrlCreateListViewItem("bbbbbbbbbbbb", $LV)
$ListView1_2 = GUICtrlCreateListViewItem("тест", $LV)
$ListView1_3 = GUICtrlCreateListViewItem("dddddddddd", $LV)
$ListView1_4 = GUICtrlCreateListViewItem("eeeeeeeeeeeeee", $LV)
$ListView1_5 = GUICtrlCreateListViewItem("ffffffffffffff", $LV)
$ListView1_6 = GUICtrlCreateListViewItem("gggggggggggggg", $LV)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$text = ""
$Dragging = False
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            ;get info on control the mouse is over
            $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
            If $Info[4] = $LV Then ;if over the Listview
                gettext()             ;get the text of the selected item
                $dragging = True ;and assume we are dragging
            Else                            ;not over the listview
                $Dragging = False
                $text = ''
            EndIf
        Case $GUI_EVENT_PRIMARYUP
            If $dragging And $text <> ""  Then
              $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
              If $Info[4] <> $LV Then
                    MouseClick("LEFT")
                    $OldClip = ClipGet()
                    ClipPut($text)
                    Send("+{Insert}")
                    ClipPut($OldClip)
                EndIf
            EndIf
            $dragging = False
            $text = ''
    EndSwitch
WEnd

Func gettext()
    Local $itemIndex = _GUICtrlListViewGetCurSel ($LV)
    $text = _GUICtrlListViewGetItemText($LV, $itemIndex,0)
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Wow, nice solution martin

This is how it would be much faster and safer (if the text is contain not latinic symbols):

Thanks MsCreator.

Good improvement, I've made a copy for my reference.

Interesting you've used Shift Insert. I always use Ctrl V in Windows and I have always used Shift Insert for DOS programs, so I wondered if that's how you came to use it. But I see from your profile that it is unlikely.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 2 weeks later...

Here is mutch more easyer way:

#include <GUIConstants.au3>
#include <GuiListView.au3>

$Form1 = GUICreate("Choices Dialog", 353, 256, 303, 219)

$Edit1 = GUICtrlCreateEdit("", 160, 32, 185, 89)
GUICtrlSetData(-1, "Edit1")

$LV = GUICtrlCreateListView("Column", 8, 24, 130, 150, $LVS_SHOWSELALWAYS)

$ListView1_0 = GUICtrlCreateListViewItem("текст кириллицы", $LV)
$ListView1_1 = GUICtrlCreateListViewItem("bbbbbbbbbbbb", $LV)
$ListView1_2 = GUICtrlCreateListViewItem("тест", $LV)
$ListView1_3 = GUICtrlCreateListViewItem("dddddddddd", $LV)
$ListView1_4 = GUICtrlCreateListViewItem("eeeeeeeeeeeeee", $LV)
$ListView1_5 = GUICtrlCreateListViewItem("ffffffffffffff", $LV)
$ListView1_6 = GUICtrlCreateListViewItem("gggggggggggggg", $LV)

GUICtrlSendMsg($LV, $LVM_SETCOLUMNWIDTH, 0, -1)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            Local $CurInfo = GUIGetCursorInfo($Form1)
            If IsArray($CurInfo) And $CurInfo[4] = $LV Then
                Local $SelText = GetSelectedText($LV)
                While IsArray($CurInfo) And $CurInfo[2] = 1
                    $CurInfo = GUIGetCursorInfo($Form1)
                    Sleep(10)
                WEnd
                If $SelText <> "" And IsArray($CurInfo) And $CurInfo[4] <> $LV Then
                    MouseClick("LEFT")
                    $OldClip = ClipGet()
                    ClipPut($SelText)
                    Send("+{Insert}")
                    ClipPut($OldClip)
                 EndIf
            EndIf
    EndSwitch
WEnd

Func GetSelectedText($ListView)
    Local $ItemIndexArr = _GUICtrlListViewGetSelectedIndices($ListView, 1)
    If Not IsArray($ItemIndexArr) Then Return SetError(1, 0, -1)
    Local $SelText = "", $Ubound = UBound($ItemIndexArr)-1, $CRLF = @CRLF
    
    For $i = 1 To $Ubound
        If $i = $Ubound Then $CRLF = ""
        $SelText &= _GUICtrlListViewGetItemText($ListView, $ItemIndexArr[$i], 0) & $CRLF
    Next
    Return $SelText
EndFunc

EDIT: Now possible to drag & drop more then one item :)

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Edited my post, now it's possible to drag & drop more then one item.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Edited my post, now it's possible to drag & drop more then one item.

:)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...