Jump to content

Need help with Hotkey system


tpt
 Share

Recommended Posts

Hello, i am new in these forums & autoit scripting. I need your help building similar hotkey system than in ventrilo (Image below).

Posted Image

Short explanation: If my cursor is in the box and i press some key my hotkey will be changed to that key.

Can anyone explain how i do this or maybe give some snippets?

Thanks in advance!

Link to comment
Share on other sites

I have one new question:

Once i have selected the hotkey, how can i make function for it?

I mean with the script that Mandanian gave me.

EDIT: Couldn't edit my last message so i had to make new reply. >.<

Edited by tpt
Link to comment
Share on other sites

Set a hotkey then press the button.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

HotKeySet('{CAPSLOCK}', '_ExcludeHotkey') 
HotKeySet('{NUMLOCK}', '_ExcludeHotkey')

Global Const $HKM_SETHOTKEY = $WM_USER + 1
Global Const $HKM_GETHOTKEY = $WM_USER + 2
Global Const $HKM_SETRULES = $WM_USER + 3

Global Const $HOTKEYF_ALT = 0x04
Global Const $HOTKEYF_CONTROL = 0x02
Global Const $HOTKEYF_EXT = 0x80; Extended key
Global Const $HOTKEYF_SHIFT = 0x01

; invalid key combinations
Global Const $HKCOMB_A = 0x8; ALT
Global Const $HKCOMB_C = 0x4; CTRL
Global Const $HKCOMB_CA = 0x40; CTRL+ALT
Global Const $HKCOMB_NONE = 0x1; Unmodified keys
Global Const $HKCOMB_S = 0x2; SHIFT
Global Const $HKCOMB_SA = 0x20; SHIFT+ALT
Global Const $HKCOMB_SC = 0x10; SHIFT+CTRL
Global Const $HKCOMB_SCA = 0x80; SHIFT+CTRL+ALT


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

$bt = GUICtrlCreateButton('Set as hotkey', 10, 50, 200, 30);
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd = _WinAPI_CreateWindowEx (0, 'msctls_hotkey32', '', BitOR($WS_CHILD, $WS_VISIBLE), 10, 10, 200, 25, $gui_Main)

_SendMessage($hWnd, $HKM_SETRULES, _
BitOR($HKCOMB_NONE, $HKCOMB_S), _                    ; invalid key combinations
BitOR(BitShift($HOTKEYF_ALT, -16), BitAND(0, 0xFFFF))); add ALT to invalid entries

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $bt
            $i_HotKey = _SendMessage($hWnd, $HKM_GETHOTKEY)
            $n_Flag = BitShift($i_HotKey, 8); high byte
            $i_HotKey = BitAND($i_HotKey, 0xFF); low byte
            $sz_Flag = ""
            If BitAND($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + "
            If BitAND($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + "
            If BitAND($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + "
            ;Msgbox(0, $sz_Flag & Chr($i_Hotkey), 'Chr(' & $i_Hotkey & ') = ' & Chr($i_Hotkey) & @CRLF & @CRLF & )
            
            HotKeySet(_GetCode($sz_Flag & Chr($i_Hotkey)), "_Hotkey")
            
            If $i_Hotkey = 20 or $i_Hotkey = 144 then
                _SendMessage($hWnd, $HKM_SETHOTKEY)
            EndIf
            
            GUICtrlSetState($bt, $GUI_DISABLE + $GUI_FOCUS)
            GUICtrlSetData($bt,"Try the hotkey out :)")
            
            _WinAPI_DestroyWindow ($hWnd)
    EndSwitch
WEnd
_WinAPI_DestroyWindow ($hWnd)

Exit

Func _Hotkey()
    MsgBox(0,"","Hotkey has been pressed.")
EndFunc

Func _GetCode($string)
    $temp = StringSplit($string, '+')
    
    $lastTerm = StringLower(StringStripWS($temp[Ubound($temp) - 1], 8))

    If StringLen($lastTerm) > 1 then
        If StringLeft($lastTerm, 1) = 'F' then
            $append = '{' & StringUpper($lastTerm) & '}'
        EndIf
    Else
        $temp = StringLower(StringRight($string, 1))
        If $temp = '!' then
            $append = '{PGUP}'
        ElseIf $temp = '"' then
            $append = '{PGDN}'
        ElseIf $temp = '$' then
            $append = '{HOME}'
        ElseIf $temp = '#' then
            $append = '{END}'
        ElseIf $temp = '-' then
            $append = '{INS}'
        Else         
            $append = StringLower(StringRight($string, 1))
        EndIf
    EndIf
    
    $hotkeyAssignment = ''
    If StringInStr($string, 'CTRL') > 0 then
        $hotkeyAssignment &= '^'
    EndIf

    If StringInStr($string, 'SHIFT') > 0 then
        $hotkeyAssignment &= '+'
    EndIf

    If StringInStr($string, 'ALT') > 0 then
        $hotkeyAssignment &= '!'
    EndIf

    $hotkeyAssignment &= $append
    
    Return $hotkeyAssignment
EndFunc

Func _ExcludeHotkey() 
    _SendMessage(_WinAPI_GetFocus(), $HKM_SETHOTKEY)
EndFunc
Link to comment
Share on other sites

Set a hotkey then press the button.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

HotKeySet('{CAPSLOCK}', '_ExcludeHotkey') 
HotKeySet('{NUMLOCK}', '_ExcludeHotkey')

Global Const $HKM_SETHOTKEY = $WM_USER + 1
Global Const $HKM_GETHOTKEY = $WM_USER + 2
Global Const $HKM_SETRULES = $WM_USER + 3

Global Const $HOTKEYF_ALT = 0x04
Global Const $HOTKEYF_CONTROL = 0x02
Global Const $HOTKEYF_EXT = 0x80; Extended key
Global Const $HOTKEYF_SHIFT = 0x01

; invalid key combinations
Global Const $HKCOMB_A = 0x8; ALT
Global Const $HKCOMB_C = 0x4; CTRL
Global Const $HKCOMB_CA = 0x40; CTRL+ALT
Global Const $HKCOMB_NONE = 0x1; Unmodified keys
Global Const $HKCOMB_S = 0x2; SHIFT
Global Const $HKCOMB_SA = 0x20; SHIFT+ALT
Global Const $HKCOMB_SC = 0x10; SHIFT+CTRL
Global Const $HKCOMB_SCA = 0x80; SHIFT+CTRL+ALT


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

$bt = GUICtrlCreateButton('Set as hotkey', 10, 50, 200, 30);
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd = _WinAPI_CreateWindowEx (0, 'msctls_hotkey32', '', BitOR($WS_CHILD, $WS_VISIBLE), 10, 10, 200, 25, $gui_Main)

_SendMessage($hWnd, $HKM_SETRULES, _
BitOR($HKCOMB_NONE, $HKCOMB_S), _                    ; invalid key combinations
BitOR(BitShift($HOTKEYF_ALT, -16), BitAND(0, 0xFFFF))); add ALT to invalid entries

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $bt
            $i_HotKey = _SendMessage($hWnd, $HKM_GETHOTKEY)
            $n_Flag = BitShift($i_HotKey, 8); high byte
            $i_HotKey = BitAND($i_HotKey, 0xFF); low byte
            $sz_Flag = ""
            If BitAND($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + "
            If BitAND($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + "
            If BitAND($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + "
            ;Msgbox(0, $sz_Flag & Chr($i_Hotkey), 'Chr(' & $i_Hotkey & ') = ' & Chr($i_Hotkey) & @CRLF & @CRLF & )
            
            HotKeySet(_GetCode($sz_Flag & Chr($i_Hotkey)), "_Hotkey")
            
            If $i_Hotkey = 20 or $i_Hotkey = 144 then
                _SendMessage($hWnd, $HKM_SETHOTKEY)
            EndIf
            
            GUICtrlSetState($bt, $GUI_DISABLE + $GUI_FOCUS)
            GUICtrlSetData($bt,"Try the hotkey out :)")
            
            _WinAPI_DestroyWindow ($hWnd)
    EndSwitch
WEnd
_WinAPI_DestroyWindow ($hWnd)

Exit

Func _Hotkey()
    MsgBox(0,"","Hotkey has been pressed.")
EndFunc

Func _GetCode($string)
    $temp = StringSplit($string, '+')
    
    $lastTerm = StringLower(StringStripWS($temp[Ubound($temp) - 1], 8))

    If StringLen($lastTerm) > 1 then
        If StringLeft($lastTerm, 1) = 'F' then
            $append = '{' & StringUpper($lastTerm) & '}'
        EndIf
    Else
        $temp = StringLower(StringRight($string, 1))
        If $temp = '!' then
            $append = '{PGUP}'
        ElseIf $temp = '"' then
            $append = '{PGDN}'
        ElseIf $temp = '$' then
            $append = '{HOME}'
        ElseIf $temp = '#' then
            $append = '{END}'
        ElseIf $temp = '-' then
            $append = '{INS}'
        Else         
            $append = StringLower(StringRight($string, 1))
        EndIf
    EndIf
    
    $hotkeyAssignment = ''
    If StringInStr($string, 'CTRL') > 0 then
        $hotkeyAssignment &= '^'
    EndIf

    If StringInStr($string, 'SHIFT') > 0 then
        $hotkeyAssignment &= '+'
    EndIf

    If StringInStr($string, 'ALT') > 0 then
        $hotkeyAssignment &= '!'
    EndIf

    $hotkeyAssignment &= $append
    
    Return $hotkeyAssignment
EndFunc

Func _ExcludeHotkey() 
    _SendMessage(_WinAPI_GetFocus(), $HKM_SETHOTKEY)
EndFunc
Thank you very much again... :lmao: But i found out that some of the hotkeys i enter does not work :) ie. f1

Any idea why it doesn't work/How to fix?

EDIT: It works flawlessy with pgdn but not with f1.

Edited by tpt
Link to comment
Share on other sites

The function is documented here: http://msdn.microsoft.com/en-us/library/bb775235(VS.85).aspx

It seems that extended keys are unhandled, or handled in a incorrect way. I can't write the entire bit that handles the extended keys, you'll have to do that yourself making educated guesses on how it should be.

I've done a little part of it, to at least fix your {F1} through {F12} problems.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

HotKeySet('{CAPSLOCK}', '_ExcludeHotkey') 
HotKeySet('{NUMLOCK}', '_ExcludeHotkey')

Global Const $HKM_SETHOTKEY = $WM_USER + 1
Global Const $HKM_GETHOTKEY = $WM_USER + 2
Global Const $HKM_SETRULES = $WM_USER + 3

Global Const $HOTKEYF_ALT = 0x04
Global Const $HOTKEYF_CONTROL = 0x02
Global Const $HOTKEYF_EXT = 0x80; Extended key
Global Const $HOTKEYF_SHIFT = 0x01

; invalid key combinations
Global Const $HKCOMB_A = 0x8; ALT
Global Const $HKCOMB_C = 0x4; CTRL
Global Const $HKCOMB_CA = 0x40; CTRL+ALT
Global Const $HKCOMB_NONE = 0x1; Unmodified keys
Global Const $HKCOMB_S = 0x2; SHIFT
Global Const $HKCOMB_SA = 0x20; SHIFT+ALT
Global Const $HKCOMB_SC = 0x10; SHIFT+CTRL
Global Const $HKCOMB_SCA = 0x80; SHIFT+CTRL+ALT


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

$bt = GUICtrlCreateButton('Set as hotkey', 10, 50, 200, 30);
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd = _WinAPI_CreateWindowEx (0, 'msctls_hotkey32', '', BitOR($WS_CHILD, $WS_VISIBLE), 10, 10, 200, 25, $gui_Main)

_SendMessage($hWnd, $HKM_SETRULES, _
BitOR($HKCOMB_NONE, $HKCOMB_S), _                    ; invalid key combinations
BitOR(BitShift($HOTKEYF_ALT, -16), BitAND(0, 0xFFFF))); add ALT to invalid entries

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $bt
            $i_HotKey = _SendMessage($hWnd, $HKM_GETHOTKEY)
            $n_Flag = BitShift($i_HotKey, 8); high byte
            $i_HotKey = BitAND($i_HotKey, 0xFF); low byte
            $sHotkey = ""
            
            If ( BitAND($i_Hotkey, 32) ) Then
                
                Switch $i_Hotkey
                    Case 112 To 124
                        $n = $i_Hotkey - 111
                        $sHotkey = "{F" & $n & "}"
                EndSwitch
            Else
                $sz_Flag = ""
                If BitAND($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + "
                If BitAND($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + "
                If BitAND($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + "
                
                
                $sHotkey = _GetCode($sz_Flag & Chr($i_Hotkey))
                
                If $i_Hotkey = 20 or $i_Hotkey = 144 then
                    _SendMessage($hWnd, $HKM_SETHOTKEY)
                EndIf
            EndIf
            
            
            MsgBox(0,"","HotKey set to: " & $sHotkey )
            HotKeySet($sHotkey, "_Hotkey")
            
            GUICtrlSetState($bt, $GUI_DISABLE + $GUI_FOCUS)
            GUICtrlSetData($bt,"Try the hotkey out ")
            
            _WinAPI_DestroyWindow ($hWnd)
    EndSwitch
WEnd
_WinAPI_DestroyWindow ($hWnd)

Exit

Func _Hotkey()
    MsgBox(0,"","Hotkey has been pressed.")
EndFunc

Func _GetCode($string)
    $temp = StringSplit($string, '+')
    
    $lastTerm = StringLower(StringStripWS($temp[Ubound($temp) - 1], 8))

    If StringLen($lastTerm) > 1 then
        If StringLeft($lastTerm, 1) = 'F' then
            $append = '{' & StringUpper($lastTerm) & '}'
        EndIf
    Else
        $temp = StringLower(StringRight($string, 1))
        If $temp = '!' then
            $append = '{PGUP}'
        ElseIf $temp = '"' then
            $append = '{PGDN}'
        ElseIf $temp = '$' then
            $append = '{HOME}'
        ElseIf $temp = '#' then
            $append = '{END}'
        ElseIf $temp = '-' then
            $append = '{INS}'
        Else         
            $append = StringLower(StringRight($string, 1))
        EndIf
    EndIf
    
    $hotkeyAssignment = ''
    If StringInStr($string, 'CTRL') > 0 then
        $hotkeyAssignment &= '^'
    EndIf

    If StringInStr($string, 'SHIFT') > 0 then
        $hotkeyAssignment &= '+'
    EndIf

    If StringInStr($string, 'ALT') > 0 then
        $hotkeyAssignment &= '!'
    EndIf

    $hotkeyAssignment &= $append
    
    Return $hotkeyAssignment
EndFunc

Func _ExcludeHotkey() 
    _SendMessage(_WinAPI_GetFocus(), $HKM_SETHOTKEY)
EndFunc
Link to comment
Share on other sites

The function is documented here: http://msdn.microsoft.com/en-us/library/bb775235(VS.85).aspx

It seems that extended keys are unhandled, or handled in a incorrect way. I can't write the entire bit that handles the extended keys, you'll have to do that yourself making educated guesses on how it should be.

I've done a little part of it, to at least fix your {F1} through {F12} problems.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

HotKeySet('{CAPSLOCK}', '_ExcludeHotkey') 
HotKeySet('{NUMLOCK}', '_ExcludeHotkey')

Global Const $HKM_SETHOTKEY = $WM_USER + 1
Global Const $HKM_GETHOTKEY = $WM_USER + 2
Global Const $HKM_SETRULES = $WM_USER + 3

Global Const $HOTKEYF_ALT = 0x04
Global Const $HOTKEYF_CONTROL = 0x02
Global Const $HOTKEYF_EXT = 0x80; Extended key
Global Const $HOTKEYF_SHIFT = 0x01

; invalid key combinations
Global Const $HKCOMB_A = 0x8; ALT
Global Const $HKCOMB_C = 0x4; CTRL
Global Const $HKCOMB_CA = 0x40; CTRL+ALT
Global Const $HKCOMB_NONE = 0x1; Unmodified keys
Global Const $HKCOMB_S = 0x2; SHIFT
Global Const $HKCOMB_SA = 0x20; SHIFT+ALT
Global Const $HKCOMB_SC = 0x10; SHIFT+CTRL
Global Const $HKCOMB_SCA = 0x80; SHIFT+CTRL+ALT


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

$bt = GUICtrlCreateButton('Set as hotkey', 10, 50, 200, 30);
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd = _WinAPI_CreateWindowEx (0, 'msctls_hotkey32', '', BitOR($WS_CHILD, $WS_VISIBLE), 10, 10, 200, 25, $gui_Main)

_SendMessage($hWnd, $HKM_SETRULES, _
BitOR($HKCOMB_NONE, $HKCOMB_S), _                    ; invalid key combinations
BitOR(BitShift($HOTKEYF_ALT, -16), BitAND(0, 0xFFFF))); add ALT to invalid entries

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $bt
            $i_HotKey = _SendMessage($hWnd, $HKM_GETHOTKEY)
            $n_Flag = BitShift($i_HotKey, 8); high byte
            $i_HotKey = BitAND($i_HotKey, 0xFF); low byte
            $sHotkey = ""
            
            If ( BitAND($i_Hotkey, 32) ) Then
                
                Switch $i_Hotkey
                    Case 112 To 124
                        $n = $i_Hotkey - 111
                        $sHotkey = "{F" & $n & "}"
                EndSwitch
            Else
                $sz_Flag = ""
                If BitAND($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + "
                If BitAND($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + "
                If BitAND($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + "
                
                
                $sHotkey = _GetCode($sz_Flag & Chr($i_Hotkey))
                
                If $i_Hotkey = 20 or $i_Hotkey = 144 then
                    _SendMessage($hWnd, $HKM_SETHOTKEY)
                EndIf
            EndIf
            
            
            MsgBox(0,"","HotKey set to: " & $sHotkey )
            HotKeySet($sHotkey, "_Hotkey")
            
            GUICtrlSetState($bt, $GUI_DISABLE + $GUI_FOCUS)
            GUICtrlSetData($bt,"Try the hotkey out ")
            
            _WinAPI_DestroyWindow ($hWnd)
    EndSwitch
WEnd
_WinAPI_DestroyWindow ($hWnd)

Exit

Func _Hotkey()
    MsgBox(0,"","Hotkey has been pressed.")
EndFunc

Func _GetCode($string)
    $temp = StringSplit($string, '+')
    
    $lastTerm = StringLower(StringStripWS($temp[Ubound($temp) - 1], 8))

    If StringLen($lastTerm) > 1 then
        If StringLeft($lastTerm, 1) = 'F' then
            $append = '{' & StringUpper($lastTerm) & '}'
        EndIf
    Else
        $temp = StringLower(StringRight($string, 1))
        If $temp = '!' then
            $append = '{PGUP}'
        ElseIf $temp = '"' then
            $append = '{PGDN}'
        ElseIf $temp = '$' then
            $append = '{HOME}'
        ElseIf $temp = '#' then
            $append = '{END}'
        ElseIf $temp = '-' then
            $append = '{INS}'
        Else         
            $append = StringLower(StringRight($string, 1))
        EndIf
    EndIf
    
    $hotkeyAssignment = ''
    If StringInStr($string, 'CTRL') > 0 then
        $hotkeyAssignment &= '^'
    EndIf

    If StringInStr($string, 'SHIFT') > 0 then
        $hotkeyAssignment &= '+'
    EndIf

    If StringInStr($string, 'ALT') > 0 then
        $hotkeyAssignment &= '!'
    EndIf

    $hotkeyAssignment &= $append
    
    Return $hotkeyAssignment
EndFunc

Func _ExcludeHotkey() 
    _SendMessage(_WinAPI_GetFocus(), $HKM_SETHOTKEY)
EndFunc
Thanks for the link/help once again. ^^
Link to comment
Share on other sites

  • 2 weeks later...

One last question.. How can i detect all mouse buttons? mouse1, mouse2, mouse3, mwheeldown, mwheelup, mouse4 and mouse5.

Thanks in advance!

just viewed this topic and i cant figure that script out u set a hotkey to show msg box thats it???? this is the closest thing to hotkey i have but i would like it so it ask for an input instead of having to press h to find the keys

you might need to modify it coz i have it setup for Tales Of Pirates _ispressed Keys are below it

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

HotKeySet('{CAPSLOCK}', '_ExcludeHotkey') 
HotKeySet('{NUMLOCK}', '_ExcludeHotkey')

Global Const $HKM_SETHOTKEY = $WM_USER + 1
Global Const $HKM_GETHOTKEY = $WM_USER + 2
Global Const $HKM_SETRULES = $WM_USER + 3

Global Const $HOTKEYF_ALT = 0x04
Global Const $HOTKEYF_CONTROL = 0x02
Global Const $HOTKEYF_EXT = 0x80; Extended key
Global Const $HOTKEYF_SHIFT = 0x01

; invalid key combinations
Global Const $HKCOMB_A = 0x8; ALT
Global Const $HKCOMB_C = 0x4; CTRL
Global Const $HKCOMB_CA = 0x40; CTRL+ALT
Global Const $HKCOMB_NONE = 0x1; Unmodified keys
Global Const $HKCOMB_S = 0x2; SHIFT
Global Const $HKCOMB_SA = 0x20; SHIFT+ALT
Global Const $HKCOMB_SC = 0x10; SHIFT+CTRL
Global Const $HKCOMB_SCA = 0x80; SHIFT+CTRL+ALT


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

$bt = GUICtrlCreateButton('Set as hotkey', 10, 50, 200, 30);
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd = _WinAPI_CreateWindowEx (0, 'msctls_hotkey32', '', BitOR($WS_CHILD, $WS_VISIBLE), 10, 10, 200, 25, $gui_Main)

_SendMessage($hWnd, $HKM_SETRULES, _
BitOR($HKCOMB_NONE, $HKCOMB_S), _                  ; invalid key combinations
BitOR(BitShift($HOTKEYF_ALT, -16), BitAND(0, 0xFFFF))); add ALT to invalid entries

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $bt
            $i_HotKey = _SendMessage($hWnd, $HKM_GETHOTKEY)
            $n_Flag = BitShift($i_HotKey, 8); high byte
            $i_HotKey = BitAND($i_HotKey, 0xFF); low byte
            $sHotkey = ""
            
            If ( BitAND($i_Hotkey, 32) ) Then
                
                Switch $i_Hotkey
                    Case 112 To 124
                        $n = $i_Hotkey - 111
                        $sHotkey = "{F" & $n & "}"
                EndSwitch
            Else
                $sz_Flag = ""
                If BitAND($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + "
                If BitAND($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + "
                If BitAND($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + "
                
                
                $sHotkey = _GetCode($sz_Flag & Chr($i_Hotkey))
                
                If $i_Hotkey = 20 or $i_Hotkey = 144 then
                    _SendMessage($hWnd, $HKM_SETHOTKEY)
                EndIf
            EndIf
            
            
            MsgBox(0,"","HotKey set to: " & $sHotkey )
            HotKeySet($sHotkey, "_Hotkey")
            
            GUICtrlSetState($bt, $GUI_DISABLE + $GUI_FOCUS)
            GUICtrlSetData($bt,"Try the hotkey out ")
            
            _WinAPI_DestroyWindow ($hWnd)
    EndSwitch
WEnd
_WinAPI_DestroyWindow ($hWnd)

Exit

Func _Hotkey()
    MsgBox(0,"","Hotkey has been pressed.")
EndFunc

Func _GetCode($string)
    $temp = StringSplit($string, '+')
    
    $lastTerm = StringLower(StringStripWS($temp[Ubound($temp) - 1], 8))

    If StringLen($lastTerm) > 1 then
        If StringLeft($lastTerm, 1) = 'F' then
            $append = '{' & StringUpper($lastTerm) & '}'
        EndIf
    Else
        $temp = StringLower(StringRight($string, 1))
        If $temp = '!' then
            $append = '{PGUP}'
        ElseIf $temp = '"' then
            $append = '{PGDN}'
        ElseIf $temp = '$' then
            $append = '{HOME}'
        ElseIf $temp = '#' then
            $append = '{END}'
        ElseIf $temp = '-' then
            $append = '{INS}'
        Else         
            $append = StringLower(StringRight($string, 1))
        EndIf
    EndIf
    
    $hotkeyAssignment = ''
    If StringInStr($string, 'CTRL') > 0 then
        $hotkeyAssignment &= '^'
    EndIf

    If StringInStr($string, 'SHIFT') > 0 then
        $hotkeyAssignment &= '+'
    EndIf

    If StringInStr($string, 'ALT') > 0 then
        $hotkeyAssignment &= '!'
    EndIf

    $hotkeyAssignment &= $append
    
    Return $hotkeyAssignment
EndFunc

Func _ExcludeHotkey() 
    _SendMessage(_WinAPI_GetFocus(), $HKM_SETHOTKEY)
EndFunc
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...