Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

HotKey UDF


  • Please log in to reply
157 replies to this topic

#1 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 01 March 2009 - 11:52 AM

LAST VERSION - 1.8 / 2.1b
25-Dec-13

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

Available functions


Spoiler


HotKey UDF Library v1.8
Previous downloads: 5027

Attached File  HotKey.au3   26.37KB   181 downloads


HotKey UDF Library v2.1b (Read here for more information)
Previous downloads: 1791

Attached File  HotKey_21b.au3   26.98KB   126 downloads


Virtual-Key (VK) Code Constants (Optional)
Previous downloads: 1576

Attached File  vkConstants.au3   5.62KB   1647 downloads


Example1

AutoIt         
#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

AutoIt         
#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

Edited by Yashied, 06 February 2014 - 06:05 PM.








#2 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 01 March 2009 - 12:22 PM

What's wrong with HotKeySet() ? This is much easier :P
*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#3 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 01 March 2009 - 01:19 PM

What's wrong with HotKeySet() ? This is much easier :P

Differences HotKeySet() from HotKeyAssign():

Removed. (See first post)

Edited by Yashied, 17 August 2009 - 08:10 PM.


#4 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 01 March 2009 - 03:32 PM

Very nice idea. :thumsup:

Unfortunately the script crashes after it exits. I'm using Vista SP1, AutoIt 3.2.12.1 :P
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#5 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 01 March 2009 - 03:34 PM

OK, with the description, i see the advantages :P Great work.
*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#6 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 01 March 2009 - 04:22 PM

Thanks for your reply. I specifically used as a hotkey code number, not the string value in HotKeySet (). When writing a complete application where necessary to keep the hotkeys code (such as the registry), it is better to use the number.

Edited by Yashied, 01 March 2009 - 04:30 PM.


#7 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 01 March 2009 - 09:14 PM

Very nice idea. :thumsup:

Unfortunately the script crashes after it exits. I'm using Vista SP1, AutoIt 3.2.12.1 :P


Try AutoIt v3.3.0.0.

#8 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 02 March 2009 - 07:55 PM

Who are interested, I updated the HotKey.au3.

:P

#9 BrammerTheHammer

BrammerTheHammer

    Seeker

  • Active Members
  • 13 posts

Posted 02 April 2009 - 11:09 PM

OMG, thank you, I have been looking for this for a long time, I was about to write a program from scratch.

I am try to make a my own hotkeys, such as Win+Alt+F calling a function which sends a Shift+Right. Using HotKeySet the alt key would randomly get passed to the active window 50% of the time. So far, using your program the alt key only gets passed if I have an Office2007 app or OpenOffice as the active window and press the windows key first.
Do you know of any way to fix this small problem, other than training myself to press the alt key first? :D

Also, is there a way to use your program to capture the windows key so that it does not open the StartMenu, but still works for the hot keys? I tried capturing using VK_LWIN but it blocked the hot keys that used CK_WIN.

I will be trying to set approximately 90 hot keys, including the blocked ones (Win+K, Win+U). I will reply to this thread with my findings.

Again, thank you, this is a vast improvement.
BTH

#10 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 06 April 2009 - 11:45 AM

This library has been updated.

:D

#11 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 16 April 2009 - 08:46 PM

OMG, thank you, I have been looking for this for a long time, I was about to write a program from scratch.

I am try to make a my own hotkeys, such as Win+Alt+F calling a function which sends a Shift+Right. Using HotKeySet the alt key would randomly get passed to the active window 50% of the time. So far, using your program the alt key only gets passed if I have an Office2007 app or OpenOffice as the active window and press the windows key first.
Do you know of any way to fix this small problem, other than training myself to press the alt key first? ^_^

Also, is there a way to use your program to capture the windows key so that it does not open the StartMenu, but still works for the hot keys? I tried capturing using VK_LWIN but it blocked the hot keys that used CK_WIN.

I will be trying to set approximately 90 hot keys, including the blocked ones (Win+K, Win+U). I will reply to this thread with my findings.

Again, thank you, this is a vast improvement.
BTH

Hi, BrammerTheHammer. I completely rewrote this library. Now she is working as I thought from the beginning. I suggest first to read the comments in the file. I have made many changes and additions.

;)

#12 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,557 posts

Posted 05 June 2009 - 03:10 PM

Looks like very strong UDF.  :D

But internal code is quite complicated.

Thanks for sharing anyway Yashied.

#13 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 05 June 2009 - 07:55 PM

Looks like very strong UDF.  :D

But internal code is quite complicated.

Thanks for sharing anyway Yashied.

Thank you, Zedna. I tried to ease this UDF, but most have no choice (if only at the expense of his work). I wrote a long time it, and then repairs, and then completely rewrote this library, and now it works exactly as I designed from the outset.

:D

#14 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,557 posts

Posted 05 June 2009 - 08:19 PM

I have no use for it now but I like such educative scripts

where you can learn something new and see what all is possible to do in Win32API/AutoIt :-)

#15 KenNichols

KenNichols

    Adventurer

  • Active Members
  • PipPip
  • 121 posts

Posted 15 June 2009 - 06:04 PM

Thanks, Works Great!

#16 hegearon

hegearon

    Seeker

  • Active Members
  • 7 posts

Posted 16 June 2009 - 07:57 PM

Looks great.

#17 nguyenbason

nguyenbason

    Adventurer

  • Validating
  • PipPip
  • 109 posts

Posted 26 June 2009 - 07:19 AM

Can i set on textbox or editbox? (Like when input something, press enter go to function)
UnderWorldVN- Just play the way you like it

#18 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,572 posts

Posted 26 June 2009 - 07:56 AM

AutoIt         
#Include <HotKey.au3> Global Const $VK_RETURN = 0x0D Global $Edit, $hEdit GUICreate('Test', 400, 400) $Edit = GUICtrlCreateEdit('', 10, 10, 380, 380) $hEdit = GUICtrlGetHandle($Edit) GUISetState() _HotKeyAssign($VK_RETURN, 'MyFunc', $HK_FLAG_NOBLOCKHOTKEY) Do Until GUIGetMsg() = -3 Func MyFunc()     If _WinAPI_GetFocus() <> $hEdit Then         Return     EndIf     ConsoleWrite('OK' & @CR) EndFunc   ;==>MyFunc


#19 nguyenbason

nguyenbason

    Adventurer

  • Validating
  • PipPip
  • 109 posts

Posted 26 June 2009 - 10:42 AM

AutoIt         
#Include <HotKey.au3> Global Const $VK_RETURN = 0x0D Global $Edit, $hEdit GUICreate('Test', 400, 400) $Edit = GUICtrlCreateEdit('', 10, 10, 380, 380) $hEdit = GUICtrlGetHandle($Edit) GUISetState() _HotKeyAssign($VK_RETURN, 'MyFunc', $HK_FLAG_NOBLOCKHOTKEY) Do Until GUIGetMsg() = -3 Func MyFunc()     If _WinAPI_GetFocus() <> $hEdit Then         Return     EndIf     ConsoleWrite('OK' & @CR) EndFunc   ;==>MyFunc

Thanks, but i tried your example but nothing happened, console has no output.
UnderWorldVN- Just play the way you like it

#20 crashburn

crashburn

    Seeker

  • Active Members
  • 9 posts

Posted 27 June 2009 - 03:05 AM

nice... i've been working allday just to find a solution for setting hotkey to a specified window, and heres the answer. ty




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users