Klehmanoff Posted October 7, 2011 Share Posted October 7, 2011 Hello there, I need a little program which sits in the background and which can take highlighted/marked text via hotkey and use it as a variable. The scenario is this: 1. We get e-mails with customer-numbers. 2. I want to double click the customer number, so it get's highlighted. 3. Then I want to press some hotkey (like Ctrg+Alt+C) which grabs the customer number as $customernumber and 4. automatically open a url like this: http://intranet/backend?customer=$customernumber Is Step 3 possible with AutoIt? If so, can you point me to the correct function or script for Step 3? I think I can do the implementation myself and then put it online for the public. Thanks a lot, Klehmanoff Link to comment Share on other sites More sharing options...
hannes08 Posted October 7, 2011 Share Posted October 7, 2011 Hello Khlemanoff, what you are looking for are the functions HotKeySet() and ShellExecute(). Use HotKeySet to define your hotkey and the action you need to do. Shellexecute opens the page in the default browser. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Klehmanoff Posted October 7, 2011 Author Share Posted October 7, 2011 Thanks, that's a great hint! But I still need a function to actually grab the currently selected text. hmmm I just realize I could invoke a Ctrl+C keystroke and let Windows grab the text to the clipboard, then grab the clipboard with AutoIt and open the browser page. But maybe it's possible to grab the highlighted text without using the clipboard? Link to comment Share on other sites More sharing options...
BrewManNH Posted October 7, 2011 Share Posted October 7, 2011 ClipPut, ClipGet If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Klehmanoff Posted October 7, 2011 Author Share Posted October 7, 2011 Why didn't I think of that!?! I'll start scripting over the weekend, I'll be back with results! Link to comment Share on other sites More sharing options...
Klehmanoff Posted October 9, 2011 Author Share Posted October 9, 2011 (edited) Alright thanks guys, I think I'm done here! :-) These are my results: expandcollapse popup; Hotkey-Script to easily grab order and customer numbers from E-Mail and pass them to a Intranet Backend or Microsoft Dynamics NAV ; Version 0.1 ; This script is licensed as public domain Dim $ClipboardBackup ; SETTINGS ; Hotkeys must be lower case! e.g. "c", not "C" ; Still have not figured out ergonomically optimal hotkeys $HotKey_CustomerNumber_1 = "c" $HotKey_CustomerNumber_2 = "{F2}" $HotKey_OrderNumber_1 = "a" $HotKey_OrderNumber_2 = "{F3}" $HotKey_Debitor_1 = "d" $HotKey_Debitor_2 = "{F4}" $Backend_URL = "http://intranet.local/display.asp?" $Backend_CustomerNumber = "customer=" $Backend_OrderNumber = "order=" $Backend_Browser = "iexplore.exe" ; HOTKEY DEFINITION HotKeySet("^!" & $HotKey_CustomerNumber_1, "OpenCustomer") HotKeySet($HotKey_CustomerNumber_2, "OpenCustomer") HotKeySet("^!" & $HotKey_OrderNumber_1, "OpenOrder") HotKeySet($HotKey_OrderNumber_2, "OpenOrder") ; for Microsoft Dynamics NAV HotKeySet("^!" & $HotKey_Debitor_1, "OpenDebitor") HotKeySet($HotKey_Debitor_2, "OpenDebitor") ; WAIT FOT HOTKEYS While 1 sleep(1) WEnd ; FUNCTIONS Func BackupClipboard() $ClipboardBackup = ClipGet() EndFunc Func RestoreClipboard() ClipPut($ClipboardBackup) EndFunc Func OpenBackend($1) BackupClipboard() Send("^c") ShellExecute($Backend_Browser, $Backend_URL & $1 & ClipGet() ) RestoreClipboard() EndFunc Func OpenCustomer() OpenBackend($Backend_CustomerNumber) EndFunc Func OpenOrder() OpenBackend($Backend_OrderNumber) EndFunc ; INCOMPLETE: Microsoft Dynamics NAV support Func OpenDebitor() ShellExecute("fin.exe") EndFunc Any comments? Edited October 9, 2011 by Klehmanoff Link to comment Share on other sites More sharing options...
Klehmanoff Posted October 9, 2011 Author Share Posted October 9, 2011 Version 0.2, now with ToggleHotkeys hotkey, to temporarily disable all hotkeys: expandcollapse popup; Hotkey-Script to easily grab order and customer numbers from E-Mail and pass them to a Intranet Backend or Microsoft Dynamics NAV ; Version 0.2 ; This script is licensed as public domain Dim $ClipboardBackup Dim $HotkeysEnabled ; SETTINGS ; Hotkeys must be lower case! e.g. "c", not "C" ; ; Not allowed, among others: Win+B,D,E,F,L,M,R,U; and Win+Shift+M ; # = Win-Key ; ^ = Ctrl ; ! = Alt ; + = Shift ; Example: "#c" = WIN+C ; ; Still have not figured out ergonomically optimal hotkeys $Hotkey_CustomerNumber_1 = "#c" $Hotkey_CustomerNumber_2 = "{F2}" $Hotkey_OrderNumber_1 = "#a" $Hotkey_OrderNumber_2 = "{F3}" $Hotkey_Debitor_1 = "#n" $Hotkey_Debitor_2 = "{F4}" ; Toggle Disabling of all custom hotkeys except this one $Hotkey_ToggleHotkeys = "#x" $Backend_URL = "http://intranet.local/display.asp?" $Backend_CustomerNumber = "customer=" $Backend_OrderNumber = "order=" $Backend_Browser = "iexplore.exe" ; BODY: Create Hotkeys and wait CreateHotkeys() While 1 sleep(100) WEnd ; FUNCTIONS Func CreateHotkeys() HotKeySet($Hotkey_CustomerNumber_1, "OpenCustomer") HotKeySet($Hotkey_CustomerNumber_2, "OpenCustomer") HotKeySet($Hotkey_OrderNumber_1, "OpenOrder") HotKeySet($Hotkey_OrderNumber_2, "OpenOrder") HotKeySet($Hotkey_Debitor_1, "OpenDebitor") HotKeySet($Hotkey_Debitor_2, "OpenDebitor") HotKeySet($Hotkey_ToggleHotkeys, "ToggleHotkeys") $HotkeysEnabled = 1 EndFunc Func ToggleHotkeys() If $HotkeysEnabled Then HotKeySet($Hotkey_CustomerNumber_1) HotKeySet($Hotkey_CustomerNumber_2) HotKeySet($Hotkey_OrderNumber_1) HotKeySet($Hotkey_OrderNumber_2) HotKeySet($Hotkey_Debitor_1) HotKeySet($Hotkey_Debitor_2) $HotkeysEnabled = 0 Else CreateHotkeys() EndIf EndFunc Func BackupClipboard() $ClipboardBackup = ClipGet() EndFunc Func RestoreClipboard() ClipPut($ClipboardBackup) EndFunc Func OpenBackend($1) BackupClipboard() Send("^c") ShellExecute($Backend_Browser, $Backend_URL & $1 & ClipGet() ) RestoreClipboard() EndFunc Func OpenCustomer() OpenBackend($Backend_CustomerNumber) EndFunc Func OpenOrder() OpenBackend($Backend_OrderNumber) EndFunc ; INCOMPLETE: Microsoft Dynamics NAV support Func OpenDebitor() ShellExecute("fin.exe") EndFunc Link to comment Share on other sites More sharing options...
Klehmanoff Posted October 9, 2011 Author Share Posted October 9, 2011 I just noticed that ClipPut/ClipGet only handles text but not binary data in the clipboard and using _ClipBoard_GetData() with the various Clipboard format seems to get a bit too complicated. So right now backing up the content of the clipboard is not 100% reliable (e.g. Images; Rich Text from Office applications). So let me ask again: is there another way to grab highlighted text other than using Ctrl+C and ClipGet? Link to comment Share on other sites More sharing options...
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