antmar904 Posted January 25, 2018 Posted January 25, 2018 Hi I work with a lot of ip addresses and host names and I would like to know if there is a way I can use AutoIT to get the "highlighted" text on my screen and do stuff with it. For example, I might be in a web application that shows me a list of ip addresses and I would like to find out the host name of that ip or other information about that ip address. If I could "highlight" the ip with my mouse then click a "HotKey" on my keyboard that I set would AutoIT be able to get the "highlighted" text whatever it maybe? Would that be possible?
Danp2 Posted January 25, 2018 Posted January 25, 2018 Not sure if this will work in your scenario, but I've done something like this in the past to retrieve the selected text from the window under the mouse cursor -- Local $tStruct = DllStructCreate($tagPOINT) ; Create a structure that defines the point to be checked. DllStructSetData($tStruct, "x", MouseGetPos(0)) DllStructSetData($tStruct, "y", MouseGetPos(1)) Local $hWnd = _WinAPI_WindowFromPoint($tStruct) ; Retrieve the window handle. $data = ControlCommand("", "", $hWnd, "GetSelected", "") Latest Webdriver UDF Release Webdriver Wiki FAQs
antmar904 Posted January 25, 2018 Author Posted January 25, 2018 (edited) I can maybe use this : and set a second hotkey that when pressed gets the selected text and do stuff with it but using this script how can I get what's in the clipboard or the variable that is holding what the selected text is? _ClipBoard_GetData ? Edited January 25, 2018 by antmar904
Moderators JLogan3o13 Posted January 25, 2018 Moderators Posted January 25, 2018 @antmar904, did you try it? Best way to find out "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!
antmar904 Posted January 25, 2018 Author Posted January 25, 2018 1 minute ago, JLogan3o13 said: @antmar904, did you try it? Best way to find out Yes I was as I posted ! This seems to work for me expandcollapse popup#include <Clipboard.au3> ;https://www.autoitscript.com/forum/topic/82471-how-to-save-selected-text-to-string/#comment-591730 HotKeySet("{ESC}", "_Mouse_Exit_App") HotKeySet("{F1}", "_MsgBox") 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 _MsgBox() Local $SelectedTxt = _ClipBoard_GetData() MsgBox(0, "", $SelectedTxt) EndFunc Func _Mouse_Exit_App() _Mouse_StopWatch($a_hMouseMod_hTimer[0], $a_hMouseMod_hTimer[1]) Exit EndFunc
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