Jump to content

Recommended Posts

Posted

Im trying to make a program that imitates copy/paste, but i cant seem to figure out how i can save the selected text to a string. Does anyone have any ideas? thanks

Posted

Im trying to make a program that imitates copy/paste, but i cant seem to figure out how i can save the selected text to a string. Does anyone have any ideas? thanks

If you want something like copy/paste you can use ClipBoard functions. Read more in help file.

Posted

no, don't want it to go through the clipboard. I want to be able to copy something without overwriting the stuff in the clipboard. I want to be able to select some text (for example this sentence) with my mouse, and then save it to a string.

Posted

no, don't want it to go through the clipboard. I want to be able to copy something without overwriting the stuff in the clipboard. I want to be able to select some text (for example this sentence) with my mouse, and then save it to a string.

If you want to do that in an edit control is very easy with _GUICtrlEdit_GetSel().
Posted

_GUICtrlEdit_GetSel() does not do what I want it to. I want to be able to select any text, in any situation just like with ctrl+c, and convert it to a string.

Posted

_GUICtrlEdit_GetSel() does not do what I want it to. I want to be able to select any text, in any situation just like with ctrl+c, and convert it to a string.

For example how can select text from a label?

  • Moderators
Posted (edited)

HotKeySet("{ESC}", "_Mouse_Exit_App")

Global $f_mouse_is_down = False
Global $i_mouse_primary = 0x01 ; 0x01 = left for primary, 0x02 = right
Global $h_mouse_mod, $h_mouse_timer
$h_mouse_timer = _Mouse_StartWatch($h_mouse_mod, "_Mouse_GetHighlight_ToClipboard", "int", "", 0, 10003, 10)

While 1
    Sleep(100000)
WEnd

Func _Mouse_GetHighlight_ToClipboard()
    If Not $f_mouse_is_down Then
        Local $a_getasync = DllCall("User32.dll", "int", "GetAsyncKeyState", "int", $i_mouse_primary)
        If Not @error And BitAND($a_getasync[0], 0x8000) = 0x8000 Then
            $f_mouse_is_down = True
            While Not @error And BitAND($a_getasync[0], 0x8000) = 0x8000
                Sleep(50)
                $a_getasync = DllCall("User32.dll", "int", "GetAsyncKeyState", "int", $i_mouse_primary)
            WEnd
            Send("^c")
            Sleep(100)
            $f_mouse_is_down = False
        EndIf
    EndIf
    Return
EndFunc

Func _Mouse_StartWatch(ByRef $h_mod, $s_func, $v_ret_type, $v_params, $h_wnd, $i_event_id, $i_event_time)
    $h_mod = DllCallbackRegister($s_func, $v_ret_type, $v_params)
    If @error Then Return SetError(@error, 1, 0)
    Local $h_timer = DllCall("User32.dll", "int", "SetTimer", _
                        "hwnd", $h_wnd, _
                        "uint", $i_event_id, _
                        "uint", $i_event_time, _
                        "ptr", DllCallbackGetPtr($h_mod))
    If @error Then Return SetError(@error, 2, 0)
    Return $h_timer[0]
EndFunc

Func _Mouse_StopWatch($h_mod, $h_timer, $h_wnd = 0)
    DllCallbackFree($h_mod)
    DllCall("User32.dll", "int", "KillTimer", "hwnd", $h_wnd, "int", $h_timer)
    If @error Then Return SetError(@error, 0, 0)
    Return 1
EndFunc

Func _Mouse_Exit_App()
    If IsDeclared("h_mouse_mod") Then _Mouse_StopWatch($h_mouse_mod, $h_mouse_timer)
    Exit
EndFunc

Edited by SmOke_N
Had to fix the IsDeclared statement

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

@SmOke_N

Very good example, thanks!

Just one thing... instead of using Send("^c") it is better to use Send("^{Insert}"), because the current method will fail if i change the default language layot to some other language than English.

 

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

  • Moderators
Posted

@SmOke_N

Very good example, thanks!

Just one thing... instead of using Send("^c") it is better to use Send("^{Insert}"), because the current method will fail if i change the default language layot to some other language than English.

Good point... I actually ended up writing a MultiEvent.au3 file using the SetTimer/DllCallback method.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

And also there is a bug with Exit, why the script not exit? the IsDeclared("h_mouse_mod") should be IsDeclared("$h_mouse_mod"), but it's still strange, it seems that script can not exit while the callback is not free...

 

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

  • Moderators
Posted

And also there is a bug with Exit, why the script not exit? the IsDeclared("h_mouse_mod") should be IsDeclared("$h_mouse_mod")

That's not correct ... :P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

That's not correct ... :P

Oops, you are right, probably i was tired yesterday :(

So, the script not exits because it's trying to stop the timer? ....

 

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

Posted

Ok, here is a little bit changed script, now it's exit as it should (we need to set timer on more than 10 ms, otherwise it will fail):

HotKeySet("{ESC}", "_Mouse_Exit_App")

Global $i_Mouse_Is_Down = False
Global $i_Mouse_Primary = 0x01 ; 0x01 = left for primary, 0x02 = right

Global $a_hMouseMod_hTimer = _Mouse_StartWatch("_Mouse_GetHighlight_ToClipboard", 0, 10001, 1000)

While 1
    Sleep(100)
WEnd

Func _Mouse_GetHighlight_ToClipboard()
    If Not $i_Mouse_Is_Down Then
        Local $a_GetAsync = DllCall("User32.dll", "int", "GetAsyncKeyState", "int", $i_Mouse_Primary)
        
        If Not @error And BitAND($a_GetAsync[0], 0x8000) = 0x8000 Then
            $i_Mouse_Is_Down = True
            
            While Not @error And BitAND($a_GetAsync[0], 0x8000) = 0x8000
                Sleep(50)
                $a_GetAsync = DllCall("User32.dll", "int", "GetAsyncKeyState", "int", $i_Mouse_Primary)
            WEnd
            
            Send("^{Insert}")
            Sleep(100)
            
            $i_Mouse_Is_Down = False
        EndIf
    EndIf
    
    Return 1
EndFunc

Func _Mouse_StartWatch($sCallback_Func, $hWnd, $iEvent_ID, $iEvent_Time)
    Local $h_Mouse_Mod = DllCallbackRegister($sCallback_Func, "int", "")
    If @error Then Return SetError(@error, 1, 0)
    
    Local $h_Timer = DllCall("User32.dll", "int", "SetTimer", _
                        "hwnd", $hWnd, _
                        "int", $iEvent_ID, _
                        "int", $iEvent_Time, _
                        "ptr", DllCallbackGetPtr($h_Mouse_Mod))
    
    If @error Then Return SetError(@error, 2, 0)
    
    Local $aRet[2] = [$h_Mouse_Mod, $h_Timer[0]]
    
    Return $aRet
EndFunc

Func _Mouse_StopWatch(ByRef $h_Mouse_Mod, ByRef $h_Timer, $hWnd = 0)
    If $h_Mouse_Mod > 0 Then
        DllCallbackFree($h_Mouse_Mod)
        $h_Mouse_Mod = 0
    EndIf
    
    If $h_Timer > 0 Then
        DllCall("User32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $h_Timer)
        If @error Then Return SetError(@error, 0, 0)
        
        $h_Timer = 0
    EndIf
    
    Return 1
EndFunc

Func _Mouse_Exit_App()
    _Mouse_StopWatch($a_hMouseMod_hTimer[0], $a_hMouseMod_hTimer[1])
    
    Exit
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

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
  • Recently Browsing   0 members

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