jvanegmond Posted April 12, 2008 Share Posted April 12, 2008 (edited) HotStrings are similar to AutoIts HotKey function but they trigger on a string of characters, instead of a key or key combination. This has been built because of popular requested from the community.Instructions for use: Download the HotString.au3 (from the GitHub link) and put it in the same directory as your script. Then try out the code example below, or use the library in your own application. Please visit https://github.com/jvanegmond/hotstrings for the download (download zip in bottom right). Or get it directly from master.Example#include <HotString.au3> HotStringSet("callme{enter}", examplefunction) While 1 Sleep(10) WEnd Func examplefunction() MsgBox(0,"","You typed callme! :)") EndFunc Edited August 9, 2014 by Manadar u0i299pg, Gianni, mesale0077 and 1 other 4 github.com/jvanegmond Link to comment Share on other sites More sharing options...
Zedna Posted April 12, 2008 Share Posted April 12, 2008 Nice! Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
James Posted April 12, 2008 Share Posted April 12, 2008 This is cool I was in need of this a year ago, gave up though After my tic-tac-toe game I should continue it Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
JustinReno Posted April 20, 2008 Share Posted April 20, 2008 Is there anychance you can put the link back up for this? Link to comment Share on other sites More sharing options...
Valuater Posted April 20, 2008 Share Posted April 20, 2008 (edited) The link is cold... I tried to browse your site, however I didn't know the title name! thx 8) Edited April 20, 2008 by Valuater Link to comment Share on other sites More sharing options...
James Posted April 20, 2008 Share Posted April 20, 2008 If I still have the file (not sure I do) I will upload it for ya'll! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
jvanegmond Posted April 1, 2009 Author Share Posted April 1, 2009 (edited) If I still have the file (not sure I do) I will upload it for ya'll!I lost the file and decided to rewrite it on request.Suggestions and code improvements are very much welcome. Especially to get rid of the ugly Adlib. :] Edited April 1, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
AlmarM Posted April 1, 2009 Share Posted April 1, 2009 Woah, thats cool. Nice work here! AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
RomanK Posted April 1, 2009 Share Posted April 1, 2009 Cool! Do I understand it right, that I can register HotStrings as I can with hotkeys, so that whereever I type the defined string (eg. in browser or open office), the script that could be running in background, will execute the defined function? [font="Courier New"]http://RomanK.hondadesigns.com[/font] Link to comment Share on other sites More sharing options...
jvanegmond Posted April 1, 2009 Author Share Posted April 1, 2009 Cool! Do I understand it right, that I can register HotStrings as I can with hotkeys, so that whereever I type the defined string (eg. in browser or open office), the script that could be running in background, will execute the defined function?Yes. github.com/jvanegmond Link to comment Share on other sites More sharing options...
RomanK Posted April 1, 2009 Share Posted April 1, 2009 (edited) wow, that is great, thx for the cornfirmation, Manadar! A few hours ago I didn't even know that HotStrings existed outside of games (cheats... which I don't use by the way) EDIT: Oh, and thank you for the code itself of course hmm, does the hotstring also get unregistered like what should be done with hotkeys when closing the autoit app? Edited April 1, 2009 by RomanK [font="Courier New"]http://RomanK.hondadesigns.com[/font] Link to comment Share on other sites More sharing options...
jvanegmond Posted April 1, 2009 Author Share Posted April 1, 2009 Well, uuh, there's really no such thing as a "HotString" in Windows. I just made one using a keyboard hook, so.. There you have it. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Authenticity Posted April 1, 2009 Share Posted April 1, 2009 I think you should rethink the buffer thing. If I have 2 functions named "a" and "b" and I press "aa" "bb" it's gonna be cool but maybe not what the user expect HotString. ;] Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 1, 2009 Share Posted April 1, 2009 I lost the file and decided to rewrite it on request. Suggestions and code improvements are very much welcome. Especially to get rid of the ugly Adlib. :] Some thoughts: [1] Perhaps it should check that the currently active window is the same before concatenating the $buffer [2] Maybe there could be a timeout so that consecutive characters have to be pressed within a certain timeframe [3] If you made a GUI (maybe even a hidden one) then you could post a message (_WinAPI_PostMessage()) to the GUI at the end of EvaluateKey. Combine that with subclassing or GUIRegisterMsg() and you could get rid of that beautiful Adlib There's no reason this couldn't become a full blown app similar to Lifehacker's Texter which is written in some other macro language WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
jvanegmond Posted April 4, 2009 Author Share Posted April 4, 2009 [3] If you made a GUI (maybe even a hidden one) then you could post a message (_WinAPI_PostMessage()) to the GUI at the end of EvaluateKey. Combine that with subclassing or GUIRegisterMsg() and you could get rid of that beautiful Adlib Brilliant. github.com/jvanegmond Link to comment Share on other sites More sharing options...
minty Posted June 15, 2009 Share Posted June 15, 2009 hey, this code is really great... i'm using it at work to monitor what's being typed and remember strings of a certain format. the only problem is that it doesn't seem to detect the ENTER key at all (ie, $keycode has no value when enter is pressed). can anyone explain why this is the case? thanks Link to comment Share on other sites More sharing options...
jvanegmond Posted June 15, 2009 Author Share Posted June 15, 2009 hey, this code is really great... i'm using it at work to monitor what's being typed and remember strings of a certain format. the only problem is that it doesn't seem to detect the ENTER key at all (ie, $keycode has no value when enter is pressed). can anyone explain why this is the case? thanks I'm using ENTER key internally to indicate a new sequence of characters. I think it is possible to remember the last 100 characters pressed and see if they match a part of the ........... Try this new version: expandcollapse popup; Authors: Manadar, GarryFrost ; Contributor: WideBoyDixon #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include-once Dim $hHook Dim $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") Dim $hmod = _WinAPI_GetModuleHandle(0) Dim $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod) Dim $buffer = "" Dim $hotstrings[1] Dim $hotfuncs[1] Dim $hWnd = GUICreate("") GUIRegisterMsg($WM_KEYDOWN, "_GUIKeyProc") ;; ========================== ;; This is your actual script. ;; ========================== ;#include <HotString.au3> HotStringSet("date","examplefunction") While 1 Sleep(10) WEnd Func examplefunction() Send("{BACKSPACE 4}") Send(@WDAY & " - " & @MON & " - " & @YEAR) EndFunc ;; ========================== ;; End of actual script. ;; The part above the start of the actual script ;; and below this comment ;; script can be put in another ;; file and included. ;; ========================== Func HotStringSet($hotstring, $func) _ArrayAdd($hotstrings, $hotstring) _ArrayAdd($hotfuncs, $func) EndFunc Func EvaluateKey($keycode) If (($keycode > 64) And ($keycode < 91)) _ ; A - Z Or (($keycode > 47) And ($keycode < 58)) Then ; 0 - 9 $buffer &= Chr($keycode) $buffer = StringRight($buffer, 50) _CheckHotkeys($buffer) EndIf EndFunc ;==>EvaluateKey Func _CheckHotkeys($s) For $i = 0 to UBound($hotstrings)-1 if ( $hotstrings[$i] = StringRight($s, StringLen($hotstrings[$i])) ) Then Call($hotfuncs[$i]) EndIf Next EndFunc Func _GUIKeyProc($hWnd, $Msg, $wParam, $lParam) EvaluateKey(Number($wParam)) EndFunc ;=========================================================== ; callback function. This function must return as quickly as possible or it will stall and block user input ;=========================================================== Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf If $wParam = $WM_KEYDOWN Then $vkKey = DllStructGetData($tKEYHOOKS, "vkCode") _WinAPI_PostMessage($hWnd, $WM_KEYDOWN, $vkKey, 0) EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExit github.com/jvanegmond Link to comment Share on other sites More sharing options...
minty Posted June 16, 2009 Share Posted June 16, 2009 What I mean is what if you want to make sure a non-character is entered after the HotString? If you look at $keycode after each keypress, certain keys aren't detected such as ESC, TAB and ENTER. It's just a bit weird (CAPS and SHIFT, etc work fine). Link to comment Share on other sites More sharing options...
jvanegmond Posted June 16, 2009 Author Share Posted June 16, 2009 They are detected, but they are not printed in the version given at the top. The newer version adds all characters to the buffer, but is only converted using the Chr function. I should probably convert them to the way AutoIt writes them down, or vice versa. github.com/jvanegmond Link to comment Share on other sites More sharing options...
celestialspring Posted July 25, 2009 Share Posted July 25, 2009 First of all a big thanks to the authors of this wonderful post. Texter was a good option but it couldn't do mouse click on writing specific text. Texter will not even come near any program, if made properly, from this text. Oh and texter used to make my programs go funny! Since then I had been looking for a good program in this relation. Something which could send both text and /or mouse actions on typing keywords. I think I have it now. Below is a simple input gui for the code to do text replacement, if you want to execute code, just add another input box to the gui and code accordingly. I have divided the original code into multiple files so as to be able to work. I am not a programmer so my attempts in creating a full fledged program will be futile. This solution works for me, change it to suit your individual needs. You will require (see codes below):autotextmain.au3autotextcode.au3autotextfunctions.au3autotextform.au3autotextmain.au3 expandcollapse popup; Authors: Manadar, GarryFrost ; Contributor: WideBoyDixon ; Gui: Celestialspring #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <autotextcode.au3> #include <autotextfunctions.au3> #include-once Dim $hHook Dim $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") Dim $hmod = _WinAPI_GetModuleHandle(0) Dim $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod) Dim $buffer = "" Dim $hotstrings[1] Dim $hotfuncs[1] Dim $hWnd = GUICreate("") GUIRegisterMsg($WM_KEYDOWN, "_GUIKeyProc") ;; ========================== ;; This is your actual script. ;; ========================== ;#include <HotString.au3> HotStringSet("test","test") While 1 Sleep(10) WEnd autotextcode.au3 expandcollapse popupFunc HotStringSet($hotstring, $func) _ArrayAdd($hotstrings, $hotstring) _ArrayAdd($hotfuncs, $func) EndFunc Func EvaluateKey($keycode) If (($keycode > 64) And ($keycode < 91)) _ ; A - Z Or (($keycode > 47) And ($keycode < 58)) Then ; 0 - 9 $buffer &= Chr($keycode) $buffer = StringRight($buffer, 50) _CheckHotkeys($buffer) EndIf EndFunc ;==>EvaluateKey Func _CheckHotkeys($s) For $i = 0 to UBound($hotstrings)-1 if ( $hotstrings[$i] = StringRight($s, StringLen($hotstrings[$i])) ) Then Call($hotfuncs[$i]) EndIf Next EndFunc Func _GUIKeyProc($hWnd, $Msg, $wParam, $lParam) EvaluateKey(Number($wParam)) EndFunc ;=========================================================== ; callback function. This function must return as quickly as possible or it will stall and block user input ;=========================================================== Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf If $wParam = $WM_KEYDOWN Then $vkKey = DllStructGetData($tKEYHOOKS, "vkCode") _WinAPI_PostMessage($hWnd, $WM_KEYDOWN, $vkKey, 0) EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExit autotextfunctions.au3 Func test() send("{BS 4}") send("this is some text") EndFunc autotextform.au3 --- This is your input GUI expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #Region ### START Koda GUI section ### Form= $Form1_1 = GUICreate("Auto-it Autotext", 332, 443, 192, 125) $Main_label = GUICtrlCreateLabel("Auto-it Autotext", 17, 8, 300, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE), $WS_EX_STATICEDGE) $Shortcutkeylabel = GUICtrlCreateLabel("Shortcut key", 17, 60, 104, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE), $WS_EX_STATICEDGE) $Shortcut_input = GUICtrlCreateInput("", 17, 112, 300, 21) $Label1 = GUICtrlCreateLabel("Code or Full Text", 17, 156, 124, 33, BitOR($SS_CENTER, $SS_CENTERIMAGE), $WS_EX_STATICEDGE) $code_input = GUICtrlCreateEdit("", 17, 208, 300, 178) GUICtrlSetData(-1, "") $ok_button = GUICtrlCreateButton("Ok", 17, 400, 97, 25, $WS_GROUP) $Cancel_button = GUICtrlCreateButton("Cancel", 193, 400, 95, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Cancel_button ;FileClose("D:\Program Files\Autoit3\Include\autotextmain.au3",1) ;FileClose("D:\Program Files\AutoIt3\Include\autotextfunctions.au3", 1) Exit Case $ok_button $shortinputfile = FileOpen("D:\Program Files\AutoIt3\Include\autotextmain.au3", 1) $codeinputfile = FileOpen("D:\Program Files\AutoIt3\Include\autotextfunctions.au3", 1) $shortinputread = GUICtrlRead($Shortcut_input) If $shortinputread = "" Then Exit If $shortinputread <> "" Then _FileWriteToLine("D:\Program Files\AutoIt3\Include\autotextmain.au3", 39, @CRLF & "HotStringSet(" & """" & $shortinputread & """" & "," & """" & $shortinputread & """" & ")", 1) FileClose($shortinputfile) ;FileWrite($shortinputfile,$shortinputread & @CRLF & While & 1 @CRLF Sleep(10) ;WEnd) EndIf $codeinputread = GUICtrlRead($code_input) If $codeinputread = "" Then Exit $len=StringLen($shortinputread) FileWrite($codeinputfile, "Func "&$shortinputread&"("&")"&@CRLF&"send("&""""&"{BS "&$len&"}"&""""&")"&@CRLF&"send("&""""&$codeinputread&""""&")"&@CRLF&"EndFunc"&@CRLF&@CRLF) FileClose($codeinputfile) Exit EndSwitch WEndA few things to note with this code1. I wasn't able to get Autoit to accept relative file names.2. I don't know how to combine the three files into one single exe file which is capable of read/write.3. I run the form code as an exe on my machine when i need to add a shortcut and keep running the autotextmain.au3 fie in the background. Would really appreciate if someone with higher programming knowledge converts this into a texter like app. 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