wo52616111 Posted October 7, 2015 Posted October 7, 2015 Many IDEs has their hotkeys, like Ctrl+C will copy one line. So if I need my ahk working in IDE, I can't get selected text by send("^c") (and ^{insert}).How to get selected text without using sendinput? Sendmessage? Dllcall?Func copyWithoutCtrlC() Local $c=ControlGetHandle("[ACTIVE]","","") _SendMessage($c,0x301) ;WM_COPY MsgBox(0,"",ClipGet()) EndFuncThis script is works in some windows(notepad, SciTE...), but did't work in IDEs and many other windows. Thanks so much.
Moderators JLogan3o13 Posted October 7, 2015 Moderators Posted October 7, 2015 Hi, wo52616111, welcome to the forum. When you say "many other windows" I doubt you are going to find a single method that works in absolutely every instance. You can, however, check out WinGetText and ControlGetText from the help file to give you some ideas. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Moderators Melba23 Posted October 7, 2015 Moderators Posted October 7, 2015 wo52616111,Just to make clear - the name of the language is AutoIt, not ahk as you used above.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
wo52616111 Posted October 7, 2015 Author Posted October 7, 2015 Hi, wo52616111, welcome to the forum. When you say "many other windows" I doubt you are going to find a single method that works in absolutely every instance. You can, however, check out WinGetText and ControlGetText from the help file to give you some ideas. I know WinGetText and ControlGetText, but they can't just get the selected text(they get all text), can they? wo52616111,Just to make clear - the name of the language is AutoIt, not ahk as you used above.M23Sorry, I can not get what you mean.
Moderators Melba23 Posted October 7, 2015 Moderators Posted October 7, 2015 wo52616111,You said this:So if I need my ahk working in IDEand I pointed out that you used the wrong name for the language - the code you posted (and the language supported by this forum ) is AutoIt.Clearer now?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
wo52616111 Posted October 7, 2015 Author Posted October 7, 2015 (edited) wo52616111,You said this:and I pointed out that you used the wrong name for the language - the code you posted (and the language supported by this forum ) is AutoIt.Clearer now?M23 Oh! I see! Sorry for that. And my code is AutoIt, that's no problem. Edited October 7, 2015 by wo52616111
Moderators JLogan3o13 Posted October 7, 2015 Moderators Posted October 7, 2015 (edited) wo52616111, you are correct they would get all text. You would then have to parse that text for the substring you're after.Can you elaborate on how the text is being selected? I am assuming the it is up to the end user to highlight text with a mouse or SHIFT + ARROW keys and then you want whatever is highlighted to be copied, is that correct?Edit: I had to rack my brain because it is an older topic, but this snippet from SmOke_N might provide some ideas for you. It still works for me on WIN 7 and 8. Edited October 7, 2015 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
wo52616111 Posted October 7, 2015 Author Posted October 7, 2015 Can you elaborate on how the text is being selected? I am assuming the it is up to the end user to highlight text with a mouse or SHIFT + ARROW keys and then you want whatever is highlighted to be copied, is that correct?Yes, you are correct. The text you get when you send("^c").
wo52616111 Posted October 7, 2015 Author Posted October 7, 2015 Edit: I had to rack my brain because it is an older topic, but this snippet from SmOke_N might provide some ideas for you. It still works for me on WIN 7 and 8.It seems is not what I want. That script still get text by using send("^c").In this context: you send Ctrl+C(Ctrl+insert) when you highlight nothing, you will get that line of text where the cursor in. Many IDEs(visual studio, sublime text...) have this feature.Now, I want to do this:Func f() If some text highlighted Local $text='@'&$textHighlighted&'@' ;if you highlight a word "apple", $text="@apple@" ClipPut($text) Send("^v") ;"@apple@" instead of "apple" Else MsgBox(0,"","NOTHING") EndFuncBut you will found that, you never see the MsgBox if you get hightlight text by using send("^c").That's the problem.
computergroove Posted October 7, 2015 Posted October 7, 2015 ClipGet() https://www.autoitscript.com/autoit3/docs/functions/ClipGet.htm After you send ^c you can set the clipboard data to a variable with ClipGet. Send("^c") Func f() $Data = ClipGet();gets data from clipboard If $Data <> "" Then Local $text='@'&$textHighlighted&'@' ;if you highlight a word "apple", $text="@apple@" ClipPut($text) Send($Data) ;"@apple@" instead of "apple" Else MsgBox(0,"","NOTHING") EndFunc Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
wo52616111 Posted October 8, 2015 Author Posted October 8, 2015 (edited) ClipGet() https://www.autoitscript.com/autoit3/docs/functions/ClipGet.htm After you send ^c you can set the clipboard data to a variable with ClipGet. Send("^c") Func f() $Data = ClipGet();gets data from clipboard If $Data <> "" Then Local $text='@'&$textHighlighted&'@' ;if you highlight a word "apple", $text="@apple@" ClipPut($text) Send($Data) ;"@apple@" instead of "apple" Else MsgBox(0,"","NOTHING") EndFunc Thanks for reply, but you don't even know what my problem is.In IDEs windows, $Data!="" FOEVER if you send("^c"). Edited October 8, 2015 by wo52616111
computergroove Posted October 8, 2015 Posted October 8, 2015 I originally saw that you wanted to get selected text without sending ^c. JLogan3o13 answered your question.Thanks for reply, but you don't even know what my problem is.In IDEs windows, $Data!="" FOEVER if you send("^c").Your last post you seemed to switch your request:Now, I want to do this:Func f() If some text highlighted Local $text='@'&$textHighlighted&'@' ;if you highlight a word "apple", $text="@apple@" ClipPut($text) Send("^v") ;"@apple@" instead of "apple" Else MsgBox(0,"","NOTHING") EndFuncBut you will found that, you never see the MsgBox if you get hightlight text by using send("^c").So I entered a clipget(). Clearly I'm missing what you are trying to accomplish. If you can get all the text in a window then you can parse that info with things like StringCompare, StringInStr, StringLen, StringLower, StringMid, StringReplace, StringRight, StringSplit, StringTrimLeft, StringTrimRight, StringUpper, StringLeftCan you restate what you want to do now? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
wo52616111 Posted October 8, 2015 Author Posted October 8, 2015 (edited) I originally saw that you wanted to get selected text without sending ^c. JLogan3o13 answered your question.Your last post you seemed to switch your request:So I entered a clipget(). Clearly I'm missing what you are trying to accomplish. If you can get all the text in a window then you can parse that info with things like StringCompare, StringInStr, StringLen, StringLower, StringMid, StringReplace, StringRight, StringSplit, StringTrimLeft, StringTrimRight, StringUpper, StringLeftCan you restate what you want to do now? I did not switch my request.I want to get the highlighted text in all programs. But you see, in IDEs, if we send("^c") when we highlighting nothing, we will get a line of text; But when we highlighting some text then send("^c"), we get the text highlighted. You will always copy some text, even you did not highlight any text.So, if you runing this script in those programs(IDEs):Send("^c") Func f() $Data = ClipGet();gets data from clipboard If $Data <> "" Then Local $text='@'&$textHighlighted&'@' ;if you highlight a word "apple", $text="@apple@" ClipPut($text) Send($Data) ;"@apple@" instead of "apple" Else MsgBox(0,"","NOTHING") EndFuncYou will never see the MsgBox, even nothing highlighted. ps.May be I describe aren't good enough, English is not my native language, and my English is a shit. Edited October 8, 2015 by wo52616111
computergroove Posted October 8, 2015 Posted October 8, 2015 To restate what I think you want to do: "Copy selected text from any program into a script.". I was unaware that if you sent ^c you would always get a line of code. Are you looking for autoit to identify if the text has been highlighted? I cannot find any data on this. Perhaps a dllcall - https://www.autoitscript.com/autoit3/docs/functions/DllCall.htm using a dll will work. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
wo52616111 Posted October 8, 2015 Author Posted October 8, 2015 (edited) To restate what I think you want to do: "Copy selected text from any program into a script.". I was unaware that if you sent ^c you would always get a line of code. Are you looking for autoit to identify if the text has been highlighted? I cannot find any data on this. Perhaps a dllcall - https://www.autoitscript.com/autoit3/docs/functions/DllCall.htm using a dll will work.You get my point finally.I know dllcall, I said at the beginning, but just don't know what function I should use. I am trying. Edited October 8, 2015 by wo52616111
computergroove Posted October 8, 2015 Posted October 8, 2015 My guess is that is in user32.dll - https://www.autoitscript.com/forum/topic/21848-functions-in-user32dll/ but it is a hell of a thing to find. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
computergroove Posted October 8, 2015 Posted October 8, 2015 What a pain it is to find this. Maybe this will help a bit.https://msdn.microsoft.com/en-us/library/windows/desktop/bb787605(v=vs.85).aspx?f=255&MSPPError=-2147217396https://msdn.microsoft.com/en-us/library/windows/desktop/bb774190(v=vs.85).aspx Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
wo52616111 Posted October 8, 2015 Author Posted October 8, 2015 (edited) What a pain it is to find this. Maybe this will help a bit.https://msdn.microsoft.com/en-us/library/windows/desktop/bb787605(v=vs.85).aspx?f=255&MSPPError=-2147217396https://msdn.microsoft.com/en-us/library/windows/desktop/bb774190(v=vs.85).aspxSorry, I still don't know how to solve the problem. I know EM_GETSELTEXT 2 days ago when I google this question, but don't know how to use it. This script can SendMessage WM_COPY(0x301):_SendMessage($c,0x301) ;WM_COPYBut I try to SendMessage EM_GETSELTEXT like this, it did't work. (I even not sure if EM_GETSELTEXT=0x43e)_SendMessage($c,0x43e) Edited October 8, 2015 by wo52616111
computergroove Posted October 8, 2015 Posted October 8, 2015 (edited) JLogan3o13 edited his post above and I tried it and it worked:expandcollapse popupHotKeySet("{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 EndFuncRun the script and highlight any text in any window and then open notepad and hit ctrl + v to see what it copied. Edited October 8, 2015 by computergroove Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
wo52616111 Posted October 9, 2015 Author Posted October 9, 2015 JLogan3o13 edited his post above and I tried it and it worked:expandcollapse popupHotKeySet("{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 EndFuncRun the script and highlight any text in any window and then open notepad and hit ctrl + v to see what it copied.I have already said three hundred times, that I don't want to get selected text by send("^c") (or ^insert).I'm tired...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now