Jump to content

HotKey UDF


Yashied
 Share

Recommended Posts

The library has been updated.

v1.8

  • Fixed the silent removal hook from the hook chain in Windows 7 and later (read this for more information). Technically, I used the Raw Input to detect when Windows will remove hook from the hook chain. If this happens, the hook will be registered again immediately.

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

was trying to troubleshoot a problem and noticed that the order in which the UDF's are included can break things
 
this works as expected, where the input strings become "None" when you first run the code...
 

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

#Include "F:\AutoIt\Resources\Funcs\_other\HotKey_Yashid\HotKey_2.1b.au3"
#Include "F:\AutoIt\Resources\Funcs\_other\HotKey_Yashid\HotKey_vkConstants.au3"
#Include "F:\AutoIt\Resources\Funcs\_other\HotKey_Yashid\HotKeyInput_1.3.au3"

$Form1 = GUICreate("Form1", 619, 445, 628, 210)
$HKI1 = _GUICtrlHKI_Create(0, 56, 55, 230, 20)
$HKI2 = _GUICtrlHKI_Create(0, 56, 89, 230, 20)
GUISetState(@SW_SHOW)

Do
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 
however this causes the inputs to be empty when you move "HotKey_2.1b.au3" to the bottom...
 

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

#Include "F:\AutoIt\Resources\Funcs\_other\HotKey_Yashid\HotKey_vkConstants.au3"
#Include "F:\AutoIt\Resources\Funcs\_other\HotKey_Yashid\HotKeyInput_1.3.au3"
#Include "F:\AutoIt\Resources\Funcs\_other\HotKey_Yashid\HotKey_2.1b.au3"

$Form1 = GUICreate("Form1", 619, 445, 628, 210)
$HKI1 = _GUICtrlHKI_Create(0, 56, 55, 230, 20)
$HKI2 = _GUICtrlHKI_Create(0, 56, 89, 230, 20)
GUISetState(@SW_SHOW)

Do
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

i was never aware that the order in which includes are added could cause a problem

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

Link to comment
Share on other sites

thanks Yashied

this UDF is a wonderful piece of work

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

Yashied - i made some notes here if you want to make HotKey and HotKeyInput UDFs more compatible with au3check with '-d -w 3 -w 4 -w 5' ...

Func _HotKey_Assign
unused var: $Error = False

Func HK_WM_ACTIVATE
add: #forceref $hWnd, $iMsg, $lParam

Func HK_WM_HOTKEY
add: #forceref $iMsg, $wParam

Func HK_WM_INPUT
add: #forceref $iMsg, $wParam

Func _GUICtrlHKI_GetHotKey
unused var: Local $Ret = 0

Func __HKI_Event
add: #forceref $hEventHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iThreadID, $iEventTime

Func __HKI_WinVer
add "Local": $tOSVI = DllStructCreate > Local $tOSVI = DllStructCreate
add "Local": $Ret = DllCall > Local $Ret = DllCall

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

no need to re-download if my suggestions were the only changes made

i would humbly suggest considering bumping the version number though, so others know the UDF was updated

thank you! :bye:

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

i keep bumping against a limitation where you cannot call _HotKey_Release() from within a function that was called with _HotKey_Assign() and i'm wondering if there is some work-a-round?

the logic is like this:

1) register hotkey for func1

2) enter func1 using the hotkey

3) unregister and unhook the hotkey

4) either just before, or just after returning from func1, re-register the hotkey

i've tried a few "tricks" to get this to work, but so far have not found a solution

unfortunately i am not proficient enough to dig into this UDF to see if this limitation can be overcome, but it would be great if it could

in my case i have a gui with the hotkey input controls that needs to be able to be shown with a hotkey, but i need to disable all hotkeys while i'm in the function containing this gui and then re-register all the hotkeys again on the flip side

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

Link to comment
Share on other sites

i can do that, but that causes other problem -- 1), there is no way to stop the key from repeating -- BitOR($HK_FLAG_NOREPEAT, $HK_FLAG_NOERROR) doesn't work -- 2), the hotkey to show the gui may or may not work - i noticed this particularly when registering Shift+ one of the arrow keys (Left, Right, etc.) where when you hold the hotkey down, the function is never called -- 3) sometimes using the gui input control to change the hotkey to open the gui does not work on the 1st try (you have to press the key combo twice to get it to display correctly in the input control)

also the gui can be shown without a hotkey, so there are 2 ways of showing it -- passing different flags to the UDF functions could be done based on how the GUI is displayed, but i think it would be better if such cases could be handled cleanly, without having to use $HK_FLAG_NOERROR

i don't think this is an unusual scenario where you have, for example, a configuration GUI that can be shown with a hotkey and other ways (such as by clicking a button or menu item) and so i think it would be ideal if this limitation could be overcome in the code by dropping the $HK_FLAG_NOERROR flag and, perhaps, adding some code to _HotKey_Release() so that it does not function until hotkeys are released and there is nothing more to do

i know that "adding some code" sounds rather dumb and i would like to offer a better fix or some example code, but allot of you guys that write these UDFs are simply working at a level which far exceeds mine, and so it is very difficult for me to follow the code, but if my suggestion is realistic, i think that would be the best and cleanest way to handle these scenarios where hotkeys need to be unregistered from a gui function called by a hotkey

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

i don't know what i'm missing here, but none of the _HotKey_Assign() examples below work when registering key combinations, except for the last one which is only a single key

#include <HotKey_vkConstants.au3>
#include <HotKey_2.1b.au3>

ConsoleWrite(_HotKey_Assign(BitOR(0x11, 0x56), "test") & @LF) ; Ctrl+V
;ConsoleWrite(_HotKey_Assign(BitOR("0x11", "0x56"), "_testMe") & @LF) ; Ctrl+V
;ConsoleWrite(_HotKey_Assign(BitOR($VK_CONTROL, $VK_V), "test") & @LF) ; Ctrl+V
;ConsoleWrite(_HotKey_Assign(BitAND($VK_CONTROL, $VK_V), "test") & @LF) ; Ctrl+V
;ConsoleWrite(_HotKey_Assign($VK_CONTROL + $VK_V, "test") & @LF) ; Ctrl+V
;ConsoleWrite(_HotKey_Assign($VK_F1, "test") & @LF) ; Ctrl+V

While 1
    Sleep(10)
WEnd

Func test()
    ConsoleWrite("ok" & @LF)
EndFunc

funny thing is, i've already implemented this UDF in a script (using multiple keys and BitOR like you're supposed to) and _HotKey_Assign() works fine there

win 7 x64

tried autoit x86 and x64, compiled and not compiled

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 can combine only one $VK_* and one up to four $CK_* constants that declared in the library. $VK_*SHIFT, $VK_*CONTROL, $VK_*MENU, and $VK_*WIN are not a bit constants and ignored by the function. Please read carefully description for the _HotKey_Assign() function.

 

BitOR($CK_CONTROL, $VK_V)

 

Global Const $CK_SHIFT = 0x0100
Global Const $CK_CONTROL = 0x0200
Global Const $CK_ALT = 0x0400
Global Const $CK_WIN = 0x0800
Link to comment
Share on other sites

i knew i was going to be sorry i asked that question :

it works in my other script because i'm using hex valuse to combine the keys

also, just wondering if you considered my >previous post?

thanks again Yashied!

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

First thanks for this great UDF but I think I've found a bug. If an hotkey with Ctrl in it, call a function sending another Ctr, then Ctrl stay pushed. Demonstration :

#include <HotKey_18.au3>

_HotKey_Assign(BitOR($CK_CONTROL, 0x0072), "test", $HK_FLAG_NOOVERLAPCALL)         ; Hotkey is Ctrl + F3

Func test()
    Send("^c")
    ConsoleWrite("Test ")
EndFunc

While True
    Sleep(500)
WEnd

So if you run the script, press Ctr + F3 then now your mouse wheel zoom in / out instead of scrooling. Push the left Ctrl to unblock the situation.

The only workaounf I've found is a bit baroque:

Func test()
    Sleep(500)
    Send("^c")
    Sleep(300)
    Send("{LCTRL}")
    Sleep(300)
    ConsoleWrite("Test ")
EndFunc

Tested with HotKey 1.8 & 2.1b + Autoit 3.3.10.2 (Win XP 32)

Link to comment
Share on other sites

  • 2 months later...

Hi there!

I'm having a problem here that the assigned hotkeys are not recognised until I unfocus and refocus the GUI window that should process them. I'm running Win 7 x64.

Minimal example:

#include <GUIConstantsEx.au3>
#include <HotKey.au3>
#include <vkConstants.au3>

Global $hWnd

$hWnd = GUICreate("HotKeys", 800, 600, -1, -1, BitOR($WS_CAPTION, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SYSMENU, $DS_CONTEXTHELP, $WS_SYSMENU, $WS_VISIBLE, $WS_CLIPCHILDREN, $WS_THICKFRAME))
GUISetState(@SW_ENABLE, $hWnd)

_HotKey_Assign($VK_RETURN, "PressedEnter", $HK_FLAG_NOBLOCKHOTKEY, $hWnd)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
   Sleep(10)
WEnd

GUIDelete($hWnd)
Exit

Func PressedEnter()
   ConsoleWrite("Pressed enter")
EndFunc

I don't get the "Pressed enter" message (i.e. hotkey is not recognised) until I click on another window and then back to this one. Am I using your UDF wrong? :ermm:

Link to comment
Share on other sites

just spotted this...

If $HK_RID Then
    GUIRegisterMsg($HK_WM_INPUT, 'HK_WM_INPUT')
    If Not __HK_Raw() Then

    EndIf
EndIf

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

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