Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

HotStrings - String hotkeys


  • Please log in to reply
55 replies to this topic

#21 celestialspring

celestialspring

    Seeker

  • Active Members
  • 38 posts

Posted 26 July 2009 - 12:09 AM

Updated Gui: Now includes options for punching code directly!

Plain Text         
#include <file.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1_1 = GUICreate("Auto-it Autotext", 352, 418) $Label1 = GUICtrlCreateLabel("Code or Full Text", 17, 156, 308, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE) $Input_chooser = GUICtrlCreateLabel("Input Type", 17, 109, 104, 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) $Main_label = GUICtrlCreateLabel("Auto-it Autotext", 17, 8, 308, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE) $Shortcut_input = GUICtrlCreateInput("", 137, 64, 191, 21) $Combo1 = GUICtrlCreateCombo("Please select", 136, 112, 191, 25) GUICtrlSetData(-1, "Text|Code") $code_input = GUICtrlCreateEdit("", 17, 200, 308, 170) GUICtrlSetData(-1, "") $ok_button = GUICtrlCreateButton("Ok", 25, 392, 97, 25, $WS_GROUP) $Cancel_button = GUICtrlCreateButton("Cancel", 201, 392, 95, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1     $Msg = GUIGetMsg()     Select         Case $Msg = $GUI_EVENT_CLOSE             Exit         Case $Msg = $Cancel_button             Exit             Case $Msg = $ok_button And $codeinputread = ""                 Exit             Case $Msg = $ok_button And $textinputread = ""                 Exit         Case $Msg = $ok_button And GUICtrlRead($Combo1) = "Text"             $shortinputfile = ("D:\Program Files\AutoIt3\Include\autotextmain.au3")             $codeinputfile = ("D:\Program Files\AutoIt3\Include\autotextfunctions.au3")             $shortinputread = GUICtrlRead($Shortcut_input)             $codeinputread = GUICtrlRead($code_input)             $textinputread = GUICtrlRead($Combo1)             $code_inputread = GUICtrlRead($Combo1)             ; opening files             FileOpen($shortinputfile, 1)             FileOpen($codeinputfile, 1)             ; Execute($writeshortcutfile)             _FileWriteToLine($shortinputfile, 39, @CRLF & "HotStringSet(" & """" & $shortinputread & """" & "," & """" & $shortinputread & """" & ")", 1)             ;Execute($writetextfile)             $len = StringLen($shortinputread)             FileWrite($codeinputfile, "Func " & $shortinputread & "(" & ")" & @CRLF & "send(" & """" & "{BS " & $len & "}" & """" & ")" & @CRLF & "send(" & """" & $codeinputread & """" & ")" & @CRLF & "EndFunc" & @CRLF & @CRLF)             ; Execute closefiles             FileClose($shortinputfile)             FileClose($codeinputfile)             Exit         Case $Msg = $ok_button And GUICtrlRead($Combo1) = "Code"             $shortinputfile = ("D:\Program Files\AutoIt3\Include\autotextmain.au3")             $codeinputfile = ("D:\Program Files\AutoIt3\Include\autotextfunctions.au3")             $shortinputread = GUICtrlRead($Shortcut_input)             $codeinputread = GUICtrlRead($code_input)             $textinputread = GUICtrlRead($Combo1)             $code_inputread = GUICtrlRead($Combo1)             ; opening files             FileOpen($shortinputfile, 1)             FileOpen($codeinputfile, 1)             ; Execute($writeshortcutfile)             _FileWriteToLine($shortinputfile, 39, @CRLF & "HotStringSet(" & """" & $shortinputread & """" & "," & """" & $shortinputread & """" & ")", 1)             ;Execute($writecodefile)             $len = StringLen($shortinputread)             FileWrite($codeinputfile, "Func " & $shortinputread & "(" & ")" & @CRLF & "send(" & """" & "{BS " & $len & "}" & """" & ")" & @CRLF & $codeinputread & @CRLF & "EndFunc" & @CRLF & @CRLF)             ; Execute closefiles             FileClose($shortinputfile)             FileClose($codeinputfile)             Exit     EndSelect WEnd;### Tidy Error -> switch is never closed in your script.;### Tidy Error -> func is never closed in your script.;### Tidy Error -> case is never closed in your script.


Screenshot:

http://yfrog.com/9fauotitj







#22 ldub

ldub

    Wayfarer

  • Active Members
  • Pip
  • 67 posts

Posted 27 July 2009 - 05:07 AM

Updated Gui: Now includes options for punching code directly!

Plain Text         
#include <file.au3>    #include <ButtonConstants.au3>  #include <ComboConstants.au3>  #include <EditConstants.au3>  #include <GUIConstantsEx.au3>  #include <StaticConstants.au3>  #include <WindowsConstants.au3>  #Region ### START Koda GUI section ### Form=  $Form1_1 = GUICreate("Auto-it Autotext", 352, 418)  $Label1 = GUICtrlCreateLabel("Code or Full Text", 17, 156, 308, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE)  $Input_chooser = GUICtrlCreateLabel("Input Type", 17, 109, 104, 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)  $Main_label = GUICtrlCreateLabel("Auto-it Autotext", 17, 8, 308, 33, BitOR($SS_CENTER,$SS_CENTERIMAGE), $WS_EX_STATICEDGE)  $Shortcut_input = GUICtrlCreateInput("", 137, 64, 191, 21)  $Combo1 = GUICtrlCreateCombo("Please select", 136, 112, 191, 25)  GUICtrlSetData(-1, "Text|Code")  $code_input = GUICtrlCreateEdit("", 17, 200, 308, 170)  GUICtrlSetData(-1, "")  $ok_button = GUICtrlCreateButton("Ok", 25, 392, 97, 25, $WS_GROUP)  $Cancel_button = GUICtrlCreateButton("Cancel", 201, 392, 95, 25, $WS_GROUP)  GUISetState(@SW_SHOW)  #EndRegion ### END Koda GUI section ###                    While 1       $Msg = GUIGetMsg()       Select         Case $Msg = $GUI_EVENT_CLOSE             Exit             Case $Msg = $Cancel_button             Exit               Case $Msg = $ok_button And $codeinputread = ""                 Exit               Case $Msg = $ok_button And $textinputread = ""                 Exit           Case $Msg = $ok_button And GUICtrlRead($Combo1) = "Text"             $shortinputfile = ("D:\Program Files\AutoIt3\Include\autotextmain.au3")             $codeinputfile = ("D:\Program Files\AutoIt3\Include\autotextfunctions.au3")             $shortinputread = GUICtrlRead($Shortcut_input)             $codeinputread = GUICtrlRead($code_input)             $textinputread = GUICtrlRead($Combo1)             $code_inputread = GUICtrlRead($Combo1)               ; opening files             FileOpen($shortinputfile, 1)             FileOpen($codeinputfile, 1)               ; Execute($writeshortcutfile)               _FileWriteToLine($shortinputfile, 39, @CRLF & "HotStringSet(" & """" & $shortinputread & """" & "," & """" & $shortinputread & """" & ")", 1)                   ;Execute($writetextfile)               $len = StringLen($shortinputread)             FileWrite($codeinputfile, "Func " & $shortinputread & "(" & ")" & @CRLF & "send(" & """" & "{BS " & $len & "}" & """" & ")" & @CRLF & "send(" & """" & $codeinputread & """" & ")" & @CRLF & "EndFunc" & @CRLF & @CRLF)               ; Execute closefiles               FileClose($shortinputfile)             FileClose($codeinputfile)                 Exit           Case $Msg = $ok_button And GUICtrlRead($Combo1) = "Code"             $shortinputfile = ("D:\Program Files\AutoIt3\Include\autotextmain.au3")             $codeinputfile = ("D:\Program Files\AutoIt3\Include\autotextfunctions.au3")             $shortinputread = GUICtrlRead($Shortcut_input)             $codeinputread = GUICtrlRead($code_input)             $textinputread = GUICtrlRead($Combo1)             $code_inputread = GUICtrlRead($Combo1)               ; opening files             FileOpen($shortinputfile, 1)             FileOpen($codeinputfile, 1)               ; Execute($writeshortcutfile)               _FileWriteToLine($shortinputfile, 39, @CRLF & "HotStringSet(" & """" & $shortinputread & """" & "," & """" & $shortinputread & """" & ")", 1)                   ;Execute($writecodefile)               $len = StringLen($shortinputread)               FileWrite($codeinputfile, "Func " & $shortinputread & "(" & ")" & @CRLF & "send(" & """" & "{BS " & $len & "}" & """" & ")" & @CRLF & $codeinputread & @CRLF & "EndFunc" & @CRLF & @CRLF)               ; Execute closefiles                   FileClose($shortinputfile)             FileClose($codeinputfile)                 Exit       EndSelect        WEnd;### Tidy Error -> switch is never closed in your script.;### Tidy Error -> func is never closed in your script.;### Tidy Error -> case is never closed in your script.  


Screenshot:

http://yfrog.com/9fauotitj



Error :


D:\- AutoIt tests\HotKey_String\Hotkey_string 2.au3(50,55) : WARNING: $codeinputread: possibly used before declaration.
Case $Msg = $ok_button And $codeinputread =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:\- AutoIt tests\HotKey_String\Hotkey_string 2.au3(53,55) : WARNING: $textinputread: possibly used before declaration.
Case $Msg = $ok_button And $textinputread =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:\- AutoIt tests\HotKey_String\Hotkey_string 2.au3 - 0 error(s), 2 warning(s)
->07:01:32 AU3Check ended.rc:1
+>07:01:32 AutoIt3Wrapper Finished
>Exit code: 0

#23 Manadar

Manadar

         

  • MVPs
  • 10,845 posts

Posted 27 July 2009 - 09:02 AM

D:\- AutoIt tests\HotKey_String\Hotkey_string 2.au3 - 0 error(s), 2 warning(s)


Error?

#24 Asaman83687

Asaman83687

    Seeker

  • Active Members
  • 7 posts

Posted 27 July 2009 - 05:56 PM

Please Help.. I found something wrong.. Wen I try to set a hotstring like this

HotStringSet("vri","_VRI")

Func _VRI()
Send("{BACKSPACE 3}")
Send("Vri™ Team")
EndFunc


AutoIt         
; Authors: Manadar, GarryFrost ; Contributor: WideBoyDixon #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include-once Opt("SendKeyDownDelay", 0) 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("vri","_VRI") While 1     Sleep(10) WEnd Func _VRI()     Send("{BACKSPACE 3}")     Send("Vri™ Team") 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


then run and type VRI.. i get an output of an non-ending Vri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™ TVri™..

Any help??

#25 Manadar

Manadar

         

  • MVPs
  • 10,845 posts

Posted 28 July 2009 - 07:48 AM

What happened is that the output from "Vri™ Team" triggered the hotkey again. I expanded the UDF a little so it suits your situation better:

AutoIt         
; 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("") Dim $globalEnable = True GUIRegisterMsg($WM_KEYDOWN, "_GUIKeyProc") ;; ========================== ;; This is your actual script. ;; ========================== ;#include <HotString.au3> Opt("SendKeyDownDelay", 0) HotStringSet("vri","_VRI") Vri™ Team While 1     Sleep(10) WEnd Func _VRI()     _EnableHotkeyCapture(False)     Send("{BACKSPACE 3}")     Send("Vri™ Team")     _EnableHotkeyCapture(True) 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 _EnableHotkeyCapture($bEnable)     $globalEnable = $bEnable     Sleep(100) ; wait for process all incoming input, so nothing is left behind EndFunc Func HotStringSet($hotstring, $func)     _ArrayAdd($hotstrings, $hotstring)     _ArrayAdd($hotfuncs, $func) EndFunc Func EvaluateKey($keycode)     If Not $globalEnable Then Return         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  


#26 Devil666

Devil666

    Seeker

  • New Members
  • 1 posts

Posted 11 January 2011 - 11:31 PM

Hello
I like you script but I'm getting some bugs:
Using the original script from the first post
1. line 41 EvaluateKey(Number($wParam)) should be _HotString_EvaluateKey(Number($wParam)) or else you'll get an error
2. dunno why but the windows I'm currently in while using the script gets unfocussed while pressing tab,right arrow key,down arrow, left/up arrow works normally :x

I'm not going to be empty handed and I've added parameters support to your script. See attachment.
How to use:
Dim $arguments[2] $arguments[0] = "CallArgArray" ; needed see Call function manual $arguments[1] = "You typed CallMe! :)" _HotStringSet("CallMe", "examplefunction", $arguments) Func examplefunction($str)     MsgBox(0,"",$str) EndFunc

Attached Files


Edited by Devil666, 11 January 2011 - 11:42 PM.


#27 Kalin

Kalin

    Prodigy

  • Banned (NOT IN USE)
  • 175 posts

Posted 12 January 2011 - 01:34 AM

This is a snippet I found on another site. It simplified the task of finishing a program I was making. It's actually very useful, but now that I know it's yours', thanks for the script!

:x

#28 Manadar

Manadar

         

  • MVPs
  • 10,845 posts

Posted 12 January 2011 - 09:38 PM

Hello
I like you script but I'm getting some bugs:
Using the original script from the first post
1. line 41 EvaluateKey(Number($wParam)) should be _HotString_EvaluateKey(Number($wParam)) or else you'll get an error
2. dunno why but the windows I'm currently in while using the script gets unfocussed while pressing tab,right arrow key,down arrow, left/up arrow works normally :x

I'm not going to be empty handed and I've added parameters support to your script. See attachment.
How to use:

Dim $arguments[2] $arguments[0] = "CallArgArray" ; needed see Call function manual $arguments[1] = "You typed CallMe! :)" _HotStringSet("CallMe", "examplefunction", $arguments) Func examplefunction($str)     MsgBox(0,"",$str) EndFunc

I don't understand why you'd want to use arguments, because in your code you can simply:

Dim $arguments[2] $arguments[0] = "CallArgArray" ; needed see Call function manual $arguments[1] = "You typed CallMe! :)" _HotStringSet("CallMe", "examplefunction") Func examplefunction()     MsgBox(0,"",$arguments[1]) EndFunc


Anyway, I am glad you liked it and got working with the code.

@Kalin, thanks too.

#29 Manadar

Manadar

         

  • MVPs
  • 10,845 posts

Posted 08 June 2011 - 09:01 AM

I've updated the UDF so that other characters than A-Z and 0-9 are now supported. You can specify characters such as {ENTER} in an AutoIt-like format (there are some differences). Also added the ability to unregister hotstrings and I've tidied the library function and variable names as to not conflict with other libraries.

Update:
- Now support for other characters than A-Z and 0-9. You can specify characters in an AutoIt-like format, such as: "Abcdef{ENTER}".
- You can now unregister a hotkey. Simply do: HotStringSet("CallMe{enter}") without specifying a function name.
- Better names for variables and function names. No more global variables $buffer, $hook and $user32 and global function _KeyProc, etc. Hopefully this won't conflict anymore with other libraries.
- Updated for v3.3.2.0 (released december 2009). Uses OnAutoItExitRegister now.

Supported keys:
{ESC}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12} {GRAVE}1234567890-={BACKSPACE} {TAB}QWERTYUIOP[]\ {CAPSLOCK}ASDFGHJKL;{ACUTE/CEDILLA} {SHIFT}ZXCVBNM,./ {CTRL}{Left Windows}{SPACE}{Right Windows}{Application}{Right Ctrl} {LEFT}{UP}{RIGHT}{DOWN} {INSERT}{HOME}{PGUP}{DELETE}{END}{PGDOWN}{Prnt Scrn}{SCROLL LOCK}{Pause} {Num Lock}{NUM DIVIDE}{NUMMULT}{NUM SUB}{NUM 7}{NUM 8}{NUM 9}{NUM PLUS}{NUM 4}{NUM 5}{NUM 6}{NUM 1}{NUM 2}{NUM 3}{NUM ENTER}{NUM 0}{NUM DECIMAL}


Modifiers are not supported, for example ^a for {CTRL}a. This is not CaSE SenSiTiVE.



Edit: Could anyone try it out and say if it works? It might all be based on my PC coincidentally configured correctly. Preferably also someone who doesn't have a US International keyboard, etc.
Edit2: Fixed some issues with it not working. Should be OK now.

Edited by Manadar, 08 June 2011 - 09:46 AM.


#30 mesale0077

mesale0077

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 474 posts

Posted 08 June 2011 - 08:08 PM

hi

"ğ, ü, ç, ö, ş" does not recognize fonts
"ğ, ü, ç, ö, ş" character does not work
why
thank you now

#31 Manadar

Manadar

         

  • MVPs
  • 10,845 posts

Posted 09 June 2011 - 06:53 AM

hi

"ğ, ü, ç, ö, ş" does not recognize fonts
"ğ, ü, ç, ö, ş" character does not work
why
thank you now

Why? Simple answer: Because they are not in the list of supported keys.

Try this UDF and run your script from SciTE and tell me the output.

AutoIt         
; Authors: Manadar, GaryFrost ; Contributor: WideBoyDixon, KaFu, Malkey #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include-once Local $_hotString_hStub_KeyProc = DllCallbackRegister("_HotString_KeyProc", "long", "int;wparam;lparam") Local $_hotString_hmod = _WinAPI_GetModuleHandle(0) Local $_hotString_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($_hotString_hStub_KeyProc), $_hotString_hmod) Local $_hotString_buffer = "" Local $_hotString_User32 = DllOpen("user32.dll") Local $_hotString_hotkeys[1] Local $_hotString_hotfuncs[1] Local $_hotString_hWnd = GUICreate("") GUIRegisterMsg($WM_COMMAND, "_HotString_GUIKeyProc") OnAutoItExitRegister("_HotString_OnAutoItExit") Func HotStringSet($hotstring, $func = "")     If $func = "" Then         $i = _ArraySearch($_hotString_hotkeys, $hotstring)         If $i = -1 Then Return         _ArrayDelete($_hotString_hotkeys, $i)         _ArrayDelete($_hotString_hotfuncs, $i)     Else         _ArrayAdd($_hotString_hotkeys, $hotstring)         _ArrayAdd($_hotString_hotfuncs, $func)     EndIf EndFunc Func _HotString_EvaluateKey($key)     If StringLen($key) > 1 Then         $_hotString_buffer &= "{" & $key & "}"     Else         $_hotString_buffer &= $key     EndIf     $_hotString_buffer = StringRight($_hotString_buffer, 250)     _HotString_CheckHotkeys($_hotString_buffer) EndFunc Func _HotString_CheckHotkeys($current)     For $i = 0 to UBound($_hotString_hotkeys)-1         if _HotString_Match($_hotString_hotkeys[$i], $current) Then             Call($_hotString_hotfuncs[$i])         EndIf     Next EndFunc Func _HotString_Match($hotkey, $current)     Return StringRight($current, StringLen($hotkey)) = $hotkey EndFunc Func _HotString_GUIKeyProc($hWnd, $Msg, $wParam, $lParam)     $aRet = DllCall('user32.dll', 'int', 'GetKeyNameText', 'int', $lParam, 'str', "", 'int', 256)     $sKeyName = $aRet[2]     If $sKeyName Then         ConsoleWrite($sKeyName & " ")         _HotString_EvaluateKey($sKeyName)     EndIf     Return 0 ; dont run autoit internal handler, not sure what it is, but message = handled so do nothing EndFunc Func _HotString_KeyProc($nCode, $wParam, $lParam)     Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)     If $nCode < 0 Then         Return _WinAPI_CallNextHookEx($_hotString_hHook, $nCode, $wParam, $lParam)     EndIf     If $wParam = $WM_KEYDOWN Then         $vkKey = DllStructGetData($tKEYHOOKS, "vkCode")         ; <a href='http://msdn.microsoft.com/en-us/library/ms646300(v=vs.85' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/ms646300(v=vs.85</a>).aspx         ; create $lParam as described, above $lParam or $tKEYHOOKS is derp         $scanCode = DllStructGetData($tKEYHOOKS, "scanCode")         $flags = DllStructGetData($tKEYHOOKS, "flags")         $lWantParam = BitShift($scanCode, -16)         $lWantParam = BitOR($lWantParam, BitShift($flags, -24))         ; post message to our local GUI          ; $WM_COMMAND instead of $WM_KEYDOWN/UP because $WM_KEYDOWN automagically consumed some chars such as up, down, enter         _WinAPI_PostMessage($_hotString_hWnd, $WM_COMMAND, $vkKey, $lWantParam)     EndIf     Return _WinAPI_CallNextHookEx($_hotString_hHook, $nCode, $wParam, $lParam) EndFunc Func _HotString_OnAutoItExit()     _WinAPI_UnhookWindowsHookEx($_hotString_hHook)     DllCallbackFree($_hotString_hStub_KeyProc)     DllClose($_hotString_User32) EndFunc


If you don't get any output, then all hope is lost.

#32 czardas

czardas

  • Active Members
  • PipPipPipPipPipPip
  • 6,957 posts

Posted 09 June 2011 - 09:35 AM

I had a little mess around with this last night. Although I'm not sure what I would use it for, it's pretty good. :huh2:

#33 Morthawt

Morthawt

    Music Maker

  • Active Members
  • PipPipPipPipPipPip
  • 526 posts

Posted 21 April 2012 - 11:51 PM

How well does this UDF handle when registering about 25 separate hot-strings to different functions in terms of processor usage? I am curious.

#34 jaberwacky

jaberwacky

    RegExp("\m/")

  • Active Members
  • PipPipPipPipPipPip
  • 3,163 posts

Posted 22 April 2012 - 04:04 AM

How well does this UDF handle when registering about 25 separate hot-strings to different functions in terms of processor usage? I am curious.


What have your experiments shown so far?

#35 Morthawt

Morthawt

    Music Maker

  • Active Members
  • PipPipPipPipPipPip
  • 526 posts

Posted 22 April 2012 - 04:18 AM

It seems to use the same amount of CPU as my one I have been making, while I am watching all the rest of the keys. Mine, however, in an attempt to reduce cpu even further had made it only watch for all the rest of the keys when I press control and included conditions to stop it watching all keys when not needed.

Either way It is a nice UDF but I prefer to make things myself, that is what I enjoy doing. So either way I am using the same CPU as this one when I have my script watching all needed input keys.

#36 Morthawt

Morthawt

    Music Maker

  • Active Members
  • PipPipPipPipPipPip
  • 526 posts

Posted 23 April 2012 - 05:49 AM

Found a problem. When you use two strings that have the same beginings, it does the first one it sees:


#include <HotString.au3> HotStringSet("notepadpp", "examplefunction") HotStringSet("notepad", "examplefunction") While 1     Sleep(10) WEnd Func examplefunction()     MsgBox(0,"","You typed callme! :)") EndFunc


#37 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 23 April 2012 - 05:57 AM

Found a problem. When you use two strings that have the same beginings, it does the first one it sees:

Of course. If there is no delimiter like space or linefeed required, the first hit is used.
*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#38 Morthawt

Morthawt

    Music Maker

  • Active Members
  • PipPipPipPipPipPip
  • 526 posts

Posted 23 April 2012 - 06:06 AM

True, I suppose you would have to pick a special key to end and start it like I do on my script. Originally I was not so hot on the idea of this script but I have to remember that this is a UDF it is not an all out program. So for what this was designed for I have to give it to the developer, it does a damn good job.

Its interesting how different people across the planet can have the exact same idea at some point in time, both presuming, perhaps, that its unique. There is no way I can code like this developer does, I just can't get into the whole windows api and how the inner workings goes.

#39 Manadar

Manadar

         

  • MVPs
  • 10,845 posts

Posted 23 April 2012 - 09:52 AM

Mine, however, in an attempt to reduce cpu even further had made it only watch for all the rest of the keys when I press control and included conditions to stop it watching all keys when not needed. Either way It is a nice UDF but I prefer to make things myself, that is what I enjoy doing. So either way I am using the same CPU as this one when I have my script watching all needed input keys.

There is no way I can code like this developer does, I just can't get into the whole windows api and how the inner workings goes.

These two comments are related. Mine checks for ALL keys ALL the time at the cost of no CPU more than just checking one key. It doesn't use a _IsPressed system and doesn't use constantly remapping with HotKey function. It uses the Windows API and it just sits there doing nothing, until a key is pressed. Then it checks if the key is part of one of your hotstrings and calls methods where appropriate.

I posted this originally in 2008 when HotStrings where not possible without writing your own solution. I came up with this based on the work and needs from other people. Only four years later, you come around, and speed becomes a small concern. "Nothing vs slow" is a simple choice for most developers. Anyway, despite this being written 4 years ago, I think this is about one of the fastest solutions you can get that work well.

Despite that there are is nothing extra written to improve performance, the little amount of code that is there is performant on its own. Better to write a little bit of fast code, rather than a lot of code to make a little bit of slow code faster.

#40 Morthawt

Morthawt

    Music Maker

  • Active Members
  • PipPipPipPipPipPip
  • 526 posts

Posted 23 April 2012 - 05:09 PM

Yeah its very nice. I was not aware of this UDF because I only use UDF's that are intrinsic to the default install of AutoIT. But it is very cool that the option is there for other people like myself who might want to make a program but perhaps have no clue how to achieve it. Similarly to yours when my program is checking all alpha-num keys it uses about 1 - 2 % of my cpu a second the same as your udf does. I just can't get into the raw windows api type of thing, too much work to learn. You did a really nice and professional job on this.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users