Jump to content

HotStrings - String hotkeys


jvanegmond
 Share

Recommended Posts

Updated Gui: Now includes options for punching code directly!

#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

Link to comment
Share on other sites

Updated Gui: Now includes options for punching code directly!

#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

Link to comment
Share on other sites

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

; 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??

Link to comment
Share on other sites

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:

; 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
Link to comment
Share on other sites

  • 1 year later...

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

hotstring.au3

Edited by Devil666
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 months later...

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
Link to comment
Share on other sites

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.

; 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")

        ; http://msdn.microsoft.com/en-us/library/ms646300(v=vs.85).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.

Link to comment
Share on other sites

  • 10 months later...

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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* [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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...