Jump to content

HotKey UDF


Yashied
 Share

Recommended Posts

Hi, sorry for my bad english....

Developing with your HotKey.au3, I have found a little bit problem:

Under XP (with Seven this doesn't happen) if I include "Hotkey.au3" but I don't assign any Hot Key, at the end of the program I receive an win32 exception error.

This seems due to the function "OnHotKeyExit ()" that in every case it executes:

DllCallbackFree($hkTb[0][4])

By the way, to avoid this, I've changed the line in:

If IsPtr( $hkTb[0][4] ) Then DllCallbackFree($hkTb[0][4])

thanks a lot for your work :-)

Edited by LordJim60
Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 month later...

LAST VERSION - 1.7 / 2.0b

17-Oct-11

The library allows to set hotkeys by using the low-level keyboard hook. Below are the main differences between HotKey UDF from the native HotKeySet() function.

  • To assign a hotkeys are used integer values ​​instead of strings as in the HotKeySet() function. This is useful, for example, to save the hotkey's values in the registry.
  • Ability to set any hotkeys including CTRL+ALT+DEL, F12, WIN+*, etc. The only exceptions are special keys such as "Fn" which do not have their own scan code.
  • Ability to utilize or pass on the specified hotkeys for other applications.
  • Ability to set hotkeys that already used by other applications.
  • Ability to set hotkeys only for the specified window(s).
  • Ability to prevent re-activation of the hotkeys when it is held down.
  • Ability to disable previously installed hotkeys without removing the hook from the hook chain, ie without losing priority.
  • Ability to block call user-defined function associated with the hotkey if the previous call has not been completed.
Here is what you can not do by using this library.
  • Set hotkey only for the CTRL, ALT, SHIFT, WIN, and any combination of this keys. Any hotkey should always include one function key. For example, ALT+A, CTRL+SHIFT+F10, etc.
  • Set hotkey for a mouse buttons.
  • Prevent using the hotkey like CTRL+ALT+DEL, CTRL+SHIFT+ESC (Windows Vista+), and similar.
  • Use more than one function key in the hotkey. For example, ALT+A+B, F1+F2, etc.
  • Use "Fn" key or any other keys that do not have their own scan code.

HotKey UDF Library v1.7

(Previous downloads: 2618)

HotKey UDF Library v2.0b (Read for more information)

(Previous downloads: 289)

Virtual-Key (VK) Code Constants (Optional)

(Previous downloads: 1576)

vkConstants.au3

Example1

#Include <HotKey.au3>

Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B

; Assign "F12" with Message() and set extended function call
_HotKey_Assign($VK_F12, 'Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL))

; Assign "CTRL-ESC" with Quit()
_HotKey_Assign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')

While 1
    Sleep(10)
WEnd

Func Message($iKey)
    MsgBox(0, 'Hot key Test Message', 'F12 (0x' & Hex($iKey, 4) & ') has been pressed!')
EndFunc   ;==>Message

Func Quit()
    Exit
EndFunc   ;==>Quit

Example2

#Include <HotKey.au3>

Global Const $VK_OEM_PLUS = 0xBB
Global Const $VK_OEM_MINUS = 0xBD

Global $Form, $Label
Global $i = 0

$Form = GUICreate('MyGUI', 200, 200)
$Label = GUICtrlCreateLabel($i, 20, 72, 160, 52, 0x01)
GUICtrlSetFont(-1, 32, 400, 0, 'Tahoma')
GUISetState()

; Assign "CTRL-(+)" with MyFunc1() and "CTRL-(-)" with MyFunc2() for created window only
_HotKey_Assign(BitOR($CK_CONTROL, $VK_OEM_PLUS), 'MyFunc1', 0, $Form)
_HotKey_Assign(BitOR($CK_CONTROL, $VK_OEM_MINUS), 'MyFunc2', 0, $Form)

Do
Until GUIGetMsg() = -3

Func MyFunc1()
    $i += 1
    GUICtrlSetData($Label, $i)
EndFunc   ;==>MyFunc1

Func MyFunc2()
    $i -= 1
    GUICtrlSetData($Label, $i)
EndFunc   ;==>MyFunc2

Example3

#Include <GUIConstants.au3>
#Include <HotKey.au3>

Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B

; Assign "F12" with Form()
_HotKey_Assign($VK_F12, 'Form')

; Assign "CTRL-ESC" with Quit()
_HotKey_Assign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')

While 1
    Sleep(10)
WEnd

Func Form()

    Local $Form, $Button, $Msg

    $Form = GUICreate('MyGUI', 350, 350, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)
    $Button = GUICtrlCreateButton('Exit', 140, 315, 70, 23)
    GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS))
    GUISetState(@SW_SHOW, $Form)

    While 1
        Switch GUIGetMsg()
            Case $Button, $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($Form)
EndFunc   ;==>Form

Func Quit()
    Exit
EndFunc   ;==>Quit

nice idea & many great word, but simple problem: any another LL hook after U can block all UDF functional.

U need ability 4 track what U hook is 1'st in chain. Any idea 4 realisation? )

Link to comment
Share on other sites

HotKey 2.0b - running obfusicator

this is with 3.3.6.1 and 3.3.7.21 beta, compile switches don't seem to matter (this is with no switches)

debugging isn't an option as this is out of my league :D

-### Obfuscation Error: Found Call() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.
>### current Func: HK_WM_HOTKEY
F:AutoIt_Funcs_OtherHotKey_HotKey.au3(735,1) Warning for line:Call($hkTb[$lParam][1], $Key)

-### Obfuscation Error: Found Call() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.
>### current Func: HK_WM_HOTKEY
F:AutoIt_Funcs_OtherHotKey_HotKey.au3(737,1) Warning for line:Call($hkTb[$lParam][1])

Func HK_WM_HOTKEY($hWnd, $iMsg, $wParam, $lParam)
Switch $hWnd
  Case $hkTb[0][11]
   Local $Key = $hkTb[$lParam][0]
   Switch $wParam
    Case 0
    Case 1
     $Key = -$Key
    Case Else
     Return
   EndSwitch
   $hkTb[0][10] += 1
   $hkTb[$lParam][8] += 1
   If $hkTb[$lParam][6] = 1 Then
        Call($hkTb[$lParam][1], $Key)
   Else
        Call($hkTb[$lParam][1])
   EndIf
   $hkTb[$lParam][8] -= 1
   $hkTb[0][10] -= 1
;~   If (@error = 0xDEAD) And (@extended = 0xBEEF) Then
;~  __HK_Error($hkTb[$lParam][1] & '(): Function does not exist or invalid number of parameters.')
;~   EndIf
EndSwitch
EndFunc   ;==>HK_WM_HOTKEY

#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Outfile=tst.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Fileversion=0.0.0.0
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_AU3Check=y
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4
#AutoIt3Wrapper_Run_Obfuscator=y
Edited by iCode

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

You have to add the functions you want to call via the hotkey to Obfuscators ignore list.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Obfuscator_Ignore_Funcs=_HK_Message,_HK_Quit
#include <HotKey_20b.au3>
Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B
; Assign "F12" with Message() and set extended function call
_HotKey_Assign($VK_F12, '_HK_Message', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL))
; Assign "CTRL-ESC" with Quit()
_HotKey_Assign(BitOR($CK_CONTROL, $VK_ESCAPE), '_HK_Quit')
While 1
 Sleep(10)
WEnd
Func _HK_Message($iKey)
 MsgBox(0, 'Hot key Test Message', 'F12 (0x' & Hex($iKey, 4) & ') has been pressed!')
EndFunc   ;==>Message
Func _HK_Quit()
 Exit
EndFunc   ;==>Quit
Link to comment
Share on other sites

thanks, i will do do that

must this be done because of the nature of the script, or because it is still being polished?

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

This is because of the nature of the script and how Obfuscator works. With _HotKey_Assign() you pass the function name as a string, the HotKey UDF transforms this string into a function call. Obfuscator looks for function calls and strips / encrypts them accordingly and replaces their occurences. There is no way Obfuscator can interpret the string in _HotKey_Assign() as a function name. Imagine you pass a function called "Test" to _HotKey_Assign(), should Obfuscator replace all strings "Test" to the obfuscated value?

Link to comment
Share on other sites

thank you very much for the detailed explanation!

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 months later...
  • Developers

nothing new.

what about my old quest: hook-track? any game 2day overlap u LL. simple...

Don't believe we care too much about your issue with game overlap issue.

You did read the forum rules I hope.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hey, I am storing my hotkeys in a settings file (ini), by writing the value of a bitor to the file. Is there any way that after reading the value from the file, I can reverse this bitor? Otherwise I will have to run a BitOr each time I run the program.

Thanks.

Link to comment
Share on other sites

  • 2 weeks later...

Ok, it's hard to explain, but I will do my best.

So for hotkeys, let's say Ctrl and Z. We have to bitor these. So like this:

$CK_CONTROL = 512

$VK_Z = 90

$Hotkey = BitOR($CK_CONTROL, $VK_Z); $Hotkey = 602

The value of $Hotkey is stored in an INI file.

Now, when I start the program, I want to read the INI file, and then reverse the BitOr like so:

$Hotkey = IniRead($SettingsINIFile, "Hotkeys", "Undo", "602)

$HotkeysArray = Un-BitOr($Hotkey); Which in theory, should return a 2 element array containing 512 and 90.

How would I go about doing this? The reason I want to do this, is so that the user can have the current hotkeys in my options menu, as well as in my menu items. Can this be done?

Thanks.

Link to comment
Share on other sites

$VK_Key = BitAND($Hotkey, 0xFF)
$CK_Flags = BitAND($Hotkey, 0xFF00)

But it unnecessary.

$Hotkey = IniRead($SettingsINIFile, "Hotkeys", "Undo", "602")
_HotKey_Assign($Hotkey, ...)
Edited by Yashied
Link to comment
Share on other sites

Yes, but I also want for it to return the original 2 keys. Basically, I want it to return the 2 keys that I BitOr'd originally. So what I want, is for it to take 602 and return both the hex values for the ctrl key and the z key. So it is like undoing the BitOr, but I want it to work for any hotkey combination. How would I go about doing that?

Link to comment
Share on other sites

$VK = BitAND($Hotkey, 0xFF)
Select 
    Case BitAND($Hotkey, $CK_SHIFT)
        $CK = $CK_SHIFT
    Case BitAND($Hotkey, $CK_CONTROL)
        $CK = $CK_CONTROL
    Case BitAND($Hotkey, $CK_ALT)
        $CK = $CK_ALT
    Case BitAND($Hotkey, $CK_WIN)
        $CK = $CK_WIN
    Case Else
        $CK = 0
EndSelect

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...