Jump to content

Recommended Posts

Posted (edited)

This is a small UDF for Hotkey (msctls_hotkey32) which allow to:

1) Create HotKey control (msctls_hotkey32)

2) Get and value(number) from HotKey control

3) Set value(number) in HotKey control

4) Get Hotkey format from Hotkey control which can be used in function HotKeySet

5) Get normal format from Hotkey control

6) Set rules for Hotkey control

Thanks to Achilles for his Hotkey example which help me to do this UDF.

Current functions:

_GuiCtrlHotKey_Create - Create a HotKey control

_GuiCtrlHotKey_GetHotkey - Get number identifying pressed keys in HotKey control

_GuiCtrlHotKey_SetHotkey - Set Hotkey in HotKey Control

_GuiCtrlHotKey_GetFormat - Get Normal and HotKey format from unique HotKey number

_GuiCtrlHotKey_GetFullInfo - Get Normal and HotKey format and also HotKey number from HotKey Control

_GuiCtrlHotKey_SetRules - Set rules for HotKey control

HotKey example (hotkey_example.au3):

#include-once
#include <hotkeys.au3>

#cs
-----------Flags for rules:-----------
    Invalid keys: (used when need to block combination of keys)
    $HKCOMB_NONE - Unmodified keys; it is blocked nothing, it is used only for "Modifiers"
    $HKCOMB_S - SHIFT
    $HKCOMB_C - CTRL
    $HKCOMB_A - ALT
    $HKCOMB_SC - SHIFT+CTRL
    $HKCOMB_SA - SHIFT+ALT
    $HKCOMB_CA - CTRL+ALT
    $HKCOMB_SCA - SHIFT+CTRL+ALT

    Modifiers: (this modifiers are established when pressed "Invalid keys")
    $HOTKEYF_SHIFT - SHIFT
    $HOTKEYF_CONTROL - CTRL
    $HOTKEYF_ALT - ALT
    $HOTKEYF_EXT - Extra key
----------------------------------------------
#ce

Global $HotKey
$gui_Main = GUICreate('Get Hotkey', 220, 90)

$bt = GUICtrlCreateButton('See Value', 10, 50, 200, 30);
GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd=_GuiCtrlHotKey_Create($gui_Main,10,10,180,25,0);  <= Create Hotkey
;_GuiCtrlHotKey_SetRules($hWnd,$HKCOMB_S)       ;   <= Set rules for Hotkey (blocks shift-key)
;_GuiCtrlHotKey_SetRules($hWnd,$HKCOMB_C,BitOr($HOTKEYF_CONTROL,$HOTKEYF_ALT)); <= Set rules for Hotkey (pressing ctrl = ctrl+alt)

Send("{NUMLOCK on}")
GUISetState()

While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit
    Case $bt
        $hotkey_info=_GuiCtrlHotKey_GetFullInfo($hWnd); <= Get Info about Hotkey
        If $hotkey_info<>-1 Then
            MsgBox(64,"Information","HotKey format: " & $hotkey_info[0] & _
                            @CRLF & "Normal format: " & $hotkey_info[1] & _
                            @CRLF & "HotKey value: " & $hotkey_info[2])         
            HotKeySet($hotkey); clear previous hotkey
            $hotkey=$hotkey_info[0]         
            HotKeySet($hotkey,"hello")
        Endif
    EndSwitch
WEnd

Func hello()
    MsgBox(64,"","Hello!")
EndFunc

Example:

hotkey_example.au3UDF:

hotkeys.au3

Edited by hunt
Posted

It isn't the same as HotKeySet() is it?

would you be so kind and tell the difference between HotKeySet() and your GuiCtrlHotKey_Create()?

Best regards,

J.

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Posted

nevermind found it by myself:

Differences HotKeySet() from HotKeyAssign():

- You can use any combination of keys such as CTRL-ALT-DEL or F12

- Ability to set repeating delay and rate (see $iDelay and $iRate parameters)

- Ability to set hot keys for the specified window (see $iTitle parameter)

- You can use hot keys to permit other program or block them (see $iFlag parameter)

- You can temporarily turn on or off set hotkeys (see _HotKeyEnable() and _HoyKeyDisable() functions

From the description HotKeySet() can be concluded that it uses "RegisterHotKey", which has several limitations.

http://msdn.microsoft.com/en-us/library/ms913104.aspx

http://www.autoitscript.com/autoit3/docs/f...s/HotKeySet.htm

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Posted (edited)

JRSmile

I have committed a small error in the topic name.

This is UDF for HotKey Control.

Edited by hunt

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
  • Recently Browsing   0 members

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