funlovin Posted February 2, 2010 Share Posted February 2, 2010 Hi, i would like to write a small app for text replacement like PhraseExpress. For expample: I type "h#" and the app would directly replace this with "home" Can maybe someone assist me? Thanks Link to comment Share on other sites More sharing options...
Mat Posted February 2, 2010 Share Posted February 2, 2010 look at this topic: http://www.autoitscript.com/forum/index.php?showtopic=68422 It should be simple enough after that... 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("h#","examplefunction") While 1 Sleep(10) WEnd Func examplefunction() Send("{BACKSPACE 2}home") 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)) Or ($keycode = 222) Then ; 0 - 9 If $keycode = 222 Then $keycode = Asc("#") $buffer &= Chr($keycode) ;Print($buffer) $a = _ArraySearch($hotstrings, $buffer) If ( $a >= 0 ) Then Call($hotfuncs[$a]) EndIf ElseIf ($keycode > 159) And ($keycode < 164) Then Return Else $buffer = "" EndIf EndFunc ;==>EvaluateKey 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 Print($s) ConsoleWrite($s & @CRLF) EndFunc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExit AutoIt Project Listing Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 2, 2010 Share Posted February 2, 2010 If you mean to do this in a particular edit control, for example, then you simply read the text from the control, parse it, and write it back in a loop. If you mean to do this globally, then you are wandering into key-logger territory, and we don't want to go there on this forum. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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