Jump to content

HotKeyInput UDF


Yashied
 Share

Recommended Posts

Link to comment
Share on other sites

  • 1 month later...

this one is giving me problems... the solution is likely something very simple i'm overlooking, but i've been staring at it too long

what should happen: the hotkey should never change

what does happen: it changes

if you run the script, look at the console output - _GUICtrlHKI_GetHotKey() is failing

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include 'F:\AutoIt\_Funcs\_Other\HotKey\_HotKey.au3'
#include 'F:\AutoIt\_Funcs\_Other\HotKey\_HotKeyInput.au3'

Opt('GUICloseOnESC', 0)
Opt('GUIEventOptions', 1)
Opt('MustDeclareVars', 1)

; HOTKEY
Global $Hk_DoSomething = '0x0458'

_Config()

While 1

Sleep(1000)

WEnd

Func _Config()

Local $exit

Local $Form_Config = GUICreate('', 120, 65, -1, -1)
Local $Input_Hk_DoSomething = _GUICtrlHKI_Create("", 10, 10, 93, 21)
Local $Button_Ok = GUICtrlCreateButton("Ok", 10, 35, 93, 25)

_KeyLock(0x062E) ; block CTRL+ALT+DEL

GUICtrlSetData($Input_Hk_DoSomething, _KeyToStr($Hk_DoSomething))

GUISetState(@SW_SHOW)

ConsoleWrite('set 1...' & @LF)
ConsoleWrite('_KeyToStr = ' & _KeyToStr($Hk_DoSomething) & @LF)
ConsoleWrite('_GUICtrlHKI_GetHotKey = ' & _GUICtrlHKI_GetHotKey($Input_Hk_DoSomething) & @LF)
ConsoleWrite('Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething) = ' & Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething)) & @LF)
ConsoleWrite('StringRight(Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething)), 4) = ' & StringRight(Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething)), 4) & @LF & @LF)

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_GUICtrlHKI_Release()
Exit

Case $Button_Ok
ExitLoop

EndSwitch
WEnd

; ASSIGN HOTKEY
$Hk_DoSomething = '0x' & StringRight(Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething)), 4)

ConsoleWrite('set 2...' & @LF)
ConsoleWrite('_KeyToStr = ' & _KeyToStr($Hk_DoSomething) & @LF)
ConsoleWrite('_GUICtrlHKI_GetHotKey = ' & _GUICtrlHKI_GetHotKey($Input_Hk_DoSomething) & @LF)
ConsoleWrite('Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething) = ' & Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething)) & @LF)
ConsoleWrite('StringRight(Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething)), 4) = ' & StringRight(Hex(_GUICtrlHKI_GetHotKey($Input_Hk_DoSomething)), 4) & @LF & @LF)

_HotKey_Assign($Hk_DoSomething)
_AssignHotkeys($Hk_DoSomething, '_DoSomething', $HK_FLAG_DEFAULT, '"this key"') ; hex key code, function to assign, hotkey flag(s), key descrip

; IF BELOW IS COMMENTED OUT, ALL WORKS AS IT SHOULD
_GUICtrlHKI_Release()

GUIDelete($Form_Config)

Sleep(500)

_Config()

EndFunc

Func _AssignHotkeys($hotkeyKeyCode, $function, $flag, $keyDescrip) ; hex key code, function to assign, hotkey flag(s), key descrip

If $hotkeyKeyCode <> '0x0000' Then
_HotKey_Assign($hotkeyKeyCode, $function, $flag)
If @error Then
MsgBox(48, '', 'Unable to set ' & $keyDescrip & ' hot-key!')
EndIf
EndIf

EndFunc

Func _DoSomething()

; do stuff

EndFunc

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

  • 2 years later...

Maybe it will be useful. Using 'HotKeySet':

$hkey = _GUICtrlHKI_GetHotKey($HotKey)
$hkeyp = _KeyToStr($hkey, "_")

  $hkeyp = StringLower($hkeyp)
  $hKeyp = StringRegExpReplace($hKeyp,"_","\1")

    $hKeyp = StringRegExpReplace($hKeyp,"alt","\!")
    $hKeyp = StringRegExpReplace($hKeyp,"shift","\+")
    $hKeyp = StringRegExpReplace($hKeyp,"ctrl","\^")
    $hKeyp = StringRegExpReplace($hKeyp,"win","\#")

    $hKeyp = StringRegExpReplace($hKeyp,"del","{Del}")
    $hKeyp = StringRegExpReplace($hKeyp,"spacebar","{Space}")
    $hKeyp = StringRegExpReplace($hKeyp,"enter","{Enter}")

    $hKeyp = StringRegExpReplace($hKeyp,"up","{Up}")
    $hKeyp = StringRegExpReplace($hKeyp,"down","{Down}")
    $hKeyp = StringRegExpReplace($hKeyp,"left","{Left}")
    $hKeyp = StringRegExpReplace($hKeyp,"right","{Right}")

    $hKeyp = StringRegExpReplace($hKeyp,"home","{Home}")
    $hKeyp = StringRegExpReplace($hKeyp,"end","{End}")
    $hKeyp = StringRegExpReplace($hKeyp,"esc","{Esc}")
    $hKeyp = StringRegExpReplace($hKeyp,"ins","{Ins}")
    $hKeyp = StringRegExpReplace($hKeyp,"pgup","{PgUp}")

    $hKeyp = StringRegExpReplace($hKeyp,"f1","{F1}")
    $hKeyp = StringRegExpReplace($hKeyp,"f2","{F2}")
    $hKeyp = StringRegExpReplace($hKeyp,"f3","{F3}")
    $hKeyp = StringRegExpReplace($hKeyp,"f4","{F4}")
    $hKeyp = StringRegExpReplace($hKeyp,"f5","{F5}")
    $hKeyp = StringRegExpReplace($hKeyp,"f6","{F6}")
    $hKeyp = StringRegExpReplace($hKeyp,"f7","{F7}")
    $hKeyp = StringRegExpReplace($hKeyp,"f8","{F8}")
    $hKeyp = StringRegExpReplace($hKeyp,"f9","{F9}")
    $hKeyp = StringRegExpReplace($hKeyp,"f10","{F10}")
    $hKeyp = StringRegExpReplace($hKeyp,"f11","{F11}")
    $hKeyp = StringRegExpReplace($hKeyp,"f12","{F12}")
    $hKeyp = StringRegExpReplace($hKeyp,"tab","{Tab}")

    $hKeyp = StringRegExpReplace($hKeyp,"prtscr","{PRINTSCREEN}")
    $hKeyp = StringRegExpReplace($hKeyp,"pause","{PAUSE}")

    $hKeyp = StringRegExpReplace($hKeyp,"num 0","{Numpad0}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 1","{Numpad1}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 2","{Numpad2}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 3","{Numpad3}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 4","{Numpad4}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 5","{Numpad5}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 6","{Numpad6}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 7","{Numpad7}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 8","{Numpad8}")
    $hKeyp = StringRegExpReplace($hKeyp,"num 9","{Numpad9}")

    $hKeyp = StringRegExpReplace($hKeyp,"num \*","{NumpadMult}")
    $hKeyp = StringRegExpReplace($hKeyp,"num \+","{NumpadAdd}")
    $hKeyp = StringRegExpReplace($hKeyp,"num -","{NumpadSub}")
    $hKeyp = StringRegExpReplace($hKeyp,"num /","{NumpadDiv}")
    $hKeyp = StringRegExpReplace($hKeyp,"num \.","{NumpadDot}")

    $hKeyp = StringRegExpReplace($hKeyp,"0x5d","{APPSKEY}")

HotKeySet($hKeyp,"hotkey")
Edited by ABSOLUTE
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...