Jump to content



Photo

HotKey UDF


  • Please log in to reply
139 replies to this topic

#21 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 27 June 2009 - 03:06 AM

GUISetAccelerators?





#22 nguyenbason

nguyenbason

    Adventurer

  • Validating
  • PipPip
  • 109 posts

Posted 27 June 2009 - 05:33 AM

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

UnderWorldVN- Just play the way you like it

#23 nguyenbason

nguyenbason

    Adventurer

  • Validating
  • PipPip
  • 109 posts

Posted 28 June 2009 - 11:56 AM

Another question Yashied, When i'm using the above example i have big problem, if i put a msgbox in
Func MyFunc()     If _WinAPI_GetFocus() <> $hEdit Then         Return     EndIf     Msgbox(0,"","a") EndFunc   ;==>MyFunc

Then it will auto disapper after 2s. Same for function, the functions will be terminated after 2s.
UnderWorldVN- Just play the way you like it

#24 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 28 June 2009 - 12:17 PM

Another question Yashied, When i'm using the above example i have big problem, if i put a msgbox in

Func MyFunc()     If _WinAPI_GetFocus() <> $hEdit Then         Return     EndIf     Msgbox(0,"","a") EndFunc   ;==>MyFunc

Then it will auto disapper after 2s. Same for function, the functions will be terminated after 2s.

MyFunc() in your case is a function of the interruption to the main program. Need to be crazy to stop the hook procedure. By the way I wrote about this in the UDF. See example 3 as should be done.

#25 nguyenbason

nguyenbason

    Adventurer

  • Validating
  • PipPip
  • 109 posts

Posted 28 June 2009 - 03:57 PM

MyFunc() in your case is a function of the interruption to the main program. Need to be crazy to stop the hook procedure. By the way I wrote about this in the UDF. See example 3 as should be done.


I got the idea. Thanks
UnderWorldVN- Just play the way you like it

#26 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,161 posts

Posted 29 June 2009 - 12:39 PM

Yashied, great function :) , thanks a lot for this one! One question, I want to utilize this UDF to capture WIN+F keypress and recover SMF from tray. Works fine, but the key is not consumed, SMF is maximized AND the standard Search Window pops-up. Is there a way to consume the keypress?
Global Const $VK_F = 0x46 _HotKeyAssign($CK_WIN + $VK_F, '__func_tray_recover', BitOR($HK_FLAG_NOOVERLAPCALL, $HK_FLAG_NOREPEAT))

Best Regards

#27 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 29 June 2009 - 01:10 PM

The library has been updated.

@nguyenbason

In version 1.6 your problem is solved.

@KaFu

I have everything works OK. Tell me, this example works for you (with version 1.6)?

#Include <HotKey.au3> Global Const $VK_F = 0x46 _HotKeyAssign($CK_WIN + $VK_F, 'MyFunc') While 1     Sleep(10) WEnd Func MyFunc()     MsgBox(0, 'Test', 'WIN-F has been pressed!') EndFunc   ;==>MyFunc

Edited by Yashied, 29 June 2009 - 01:34 PM.


#28 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,161 posts

Posted 29 June 2009 - 01:40 PM

Works now as desired :) , thanks for the fast response!
Best Regards

#29 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 29 June 2009 - 01:49 PM

I am glad that you liked my UDF.

:)

#30 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,072 posts

Posted 29 June 2009 - 11:32 PM

Yashied, this is an excellent program. I had thought HotKeySet() was using a keyboard hook at first, but after working with your code, I realized - apparently not! In fact, the whole purpose of the _AsyncHotKeySet UDF (rewrite, in my signature) was because certain applications/games were not recognizing the hotkeys I was pressing when set with HotKeySet(). But using your code, no problem - I no longer need _AsyncHotKeySet to poll the status of keys.

I think you have an awesome set of features, and I'd hate to bother you for another one - but its definitely something possible to do, it just requires a bit of tinkering around... Anyway, what I was wondering is if you could add the ability to provide a 'hotkey release' message. This is something I added in my _AsyncHotKeySet code, and though its probably a bit less complicated then adding it to your code, it does give you an idea of how it could possibly be done.

I'd add another flag to your code, something like '$HK_FLAG_CALLONRELEASE', which would require either that:
A.) your code waits for the initial hotkey, just takes note that the hotkey was pressed, and then when it sees the complete hotkey has been released, it calls the given function, or
B.) that you call the same function for initial hotkey press, and then on hotkey release.

I think A.) would make more sense as you wouldn't want to have two flags causing a required parameter to a function (in B.)'s case, a 'pressed/released' parameter)

Even though you might not see it, there's big potential in the hotkey 'release' message. A program can execute a given set of commands *only* after the key is released, or it could execute a set of commands on initial hotkey press and only terminate them when the hotkey is released. This could be useful for a bunch of things, but if I'd have to give an example right off the bat: lets say a gamer wanted to have some activity repeated while a key is held down, and stopped when it's released - this would be the perfect method. Or if they needed something done at precisely the right time - they could hold down the hotkey in anticipation, and release it to have the actual code execute.

*edit: Just for clarification: I don't need it for cheats - typically I'll just use cheatcodes or trainers for that :) . What I have used it for though is grabbing music (setting an app to start recording (& then stop), or even to grab screenshots)

Anyway, thanks again for your great work. It's really nice to have Hotkeys that work consistently across the board (unlike HotKeySet)

-Ascend4nt

Edited by ascendant, 30 June 2009 - 06:07 PM.


#31 nguyenbason

nguyenbason

    Adventurer

  • Validating
  • PipPip
  • 109 posts

Posted 30 June 2009 - 01:46 AM

The library has been updated.

@nguyenbason

In version 1.6 your problem is solved.

@KaFu

I have everything works OK. Tell me, this example works for you (with version 1.6)?

#Include <HotKey.au3> Global Const $VK_F = 0x46 _HotKeyAssign($CK_WIN + $VK_F, 'MyFunc') While 1     Sleep(10) WEnd Func MyFunc()     MsgBox(0, 'Test', 'WIN-F has been pressed!') EndFunc   ;==>MyFunc

Thanks Yashied,

Let me try it :)

Edit: Work very very good. Thanks :)

Edited by nguyenbason, 30 June 2009 - 02:24 AM.

UnderWorldVN- Just play the way you like it

#32 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 01 July 2009 - 03:03 PM

Yashied, this is an excellent program. I had thought HotKeySet() was using a keyboard hook at first, but after working with your code, I realized - apparently not! In fact, the whole purpose of the _AsyncHotKeySet UDF (rewrite, in my signature) was because certain applications/games were not recognizing the hotkeys I was pressing when set with HotKeySet(). But using your code, no problem - I no longer need _AsyncHotKeySet to poll the status of keys.

I think you have an awesome set of features, and I'd hate to bother you for another one - but its definitely something possible to do, it just requires a bit of tinkering around... Anyway, what I was wondering is if you could add the ability to provide a 'hotkey release' message. This is something I added in my _AsyncHotKeySet code, and though its probably a bit less complicated then adding it to your code, it does give you an idea of how it could possibly be done.

I'd add another flag to your code, something like '$HK_FLAG_CALLONRELEASE', which would require either that:
A.) your code waits for the initial hotkey, just takes note that the hotkey was pressed, and then when it sees the complete hotkey has been released, it calls the given function, or
B.) that you call the same function for initial hotkey press, and then on hotkey release.

I think A.) would make more sense as you wouldn't want to have two flags causing a required parameter to a function (in B.)'s case, a 'pressed/released' parameter)

Even though you might not see it, there's big potential in the hotkey 'release' message. A program can execute a given set of commands *only* after the key is released, or it could execute a set of commands on initial hotkey press and only terminate them when the hotkey is released. This could be useful for a bunch of things, but if I'd have to give an example right off the bat: lets say a gamer wanted to have some activity repeated while a key is held down, and stopped when it's released - this would be the perfect method. Or if they needed something done at precisely the right time - they could hold down the hotkey in anticipation, and release it to have the actual code execute.

*edit: Just for clarification: I don't need it for cheats - typically I'll just use cheatcodes or trainers for that :) . What I have used it for though is grabbing music (setting an app to start recording (& then stop), or even to grab screenshots)

Anyway, thanks again for your great work. It's really nice to have Hotkeys that work consistently across the board (unlike HotKeySet)

-Ascend4nt

ascendant, I suggest you test the HotKey UDF v1.7 beta. I have defined the $HK_FLAG_POSTCALL flag. See details inside the UDF. Here is a simple example of using this flag.

AutoIt         
#Include <HotKey_17_beta.au3> Global Const $VK_ESCAPE = 0x1B Global Const $VK_F12 = 0x7B _HotKeyAssign($VK_F12, 'MyFunc', BitOR($HK_FLAG_DEFAULT, $HK_FLAG_EXTENDEDCALL, $HK_FLAG_POSTCALL)) _HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit') While 1     Sleep(10) WEnd Func MyFunc($iKey)     If $iKey > 0 Then         ConsoleWrite('F12 (0x' & Hex($iKey, 4) & ') pressed!' & @CR)     Else         MsgBox(0, 'Hot key Test Message', 'F12 (0x' & Hex(Abs($iKey), 4) & ') has been released!')     EndIf EndFunc   ;==>MyFunc Func Quit()     Exit EndFunc   ;==>Quit
Attached File  HotKey_17_beta.au3   24.35K   436 downloads

Remark.
There is a basic principle on which based work this library - the next hot key will NOT work until the previous will not be released.

#33 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,072 posts

Posted 01 July 2009 - 10:43 PM

ascendant, I suggest you test the HotKey UDF v1.7 beta. I have defined the $HK_FLAG_POSTCALL flag. See details inside the UDF. ...

Remark.
There is a basic principle on which based work this library - the next hot key will NOT work until the previous will not be released.


Yashied, thank you for your work, much appreciated. However, just a couple of questions:

1. If I were to use a modifier like Ctrl+Alt along with F12, it will send a 'Release' message even if I'm still holding down Ctrl+Alt. Is that the intended behavior, to ignore modifier keys?

2. If I hold down Ctrl+Alt+F12, then release Ctrl+Alt, and then press say 'Shift' and finally release F12 (even releasing Shift too), the function never gets the 'Released' message. Same goes for re-pressing Ctrl or Alt, and then releasing all three - the Released message is never sent.

Thanks again though!

Had I the patience to try and understand your code I might try and see what the problem is, but uncommented code for me is a nightmare :)

#34 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 02 July 2009 - 08:32 AM

Yashied, thank you for your work, much appreciated. However, just a couple of questions:

1. If I were to use a modifier like Ctrl+Alt along with F12, it will send a 'Release' message even if I'm still holding down Ctrl+Alt. Is that the intended behavior, to ignore modifier keys?

2. If I hold down Ctrl+Alt+F12, then release Ctrl+Alt, and then press say 'Shift' and finally release F12 (even releasing Shift too), the function never gets the 'Released' message. Same goes for re-pressing Ctrl or Alt, and then releasing all three - the Released message is never sent.

Thanks again though!

Had I the patience to try and understand your code I might try and see what the problem is, but uncommented code for me is a nightmare :)

Thanks to you, ascendant. But take into account all the nuances are not trivial task, especially in the hook. In this case, the code will be in x8 more and less reliable. It may be more reasonable to implement it in a particular case, rather than to write a universal procedure, thereby sacrificing its core strengths. I decided to take a timeout for this job and leave until version 1.6. But if the 1.7 beta to something interesting, you can use it, it is fully working.

Once again thank you for your understanding of this material, I hope I will come back to this later.

Good luck.

:)

#35 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,161 posts

Posted 07 July 2009 - 08:48 AM

Yashied, working with your UDF and in connection to my last request... would it be possible to add a flag to the function call, with which the user can chose whether the key is consumed or not?
Best Regards

#36 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 07 July 2009 - 08:57 AM

Yashied, working with your UDF and in connection to my last request... would it be possible to add a flag to the function call, with which the user can chose whether the key is consumed or not?
Best Regards

$HK_FLAG_NOBLOCKHOTKEY not fit?

#37 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,161 posts

Posted 07 July 2009 - 09:01 AM

Read... think... post... messed up the sequence :) , thanks for the fast reply!

#38 rexx

rexx

    Wayfarer

  • Active Members
  • Pip
  • 65 posts

Posted 17 August 2009 - 12:44 PM

Hi, thanks for this great UDF!
But I have a question, why the mouse buttons are not supported?
Now I use AsyncHotKeySet() to set mouse hotkeys, but it can not use modifiers.
Is it possible to use mouse buttons as hotkey in your UDF?

#39 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 17 August 2009 - 02:03 PM

No, the mouse is not supported, because UDF is based on a hook. Hook for the mouse - this is from another area.

#40 Jeff West

Jeff West

    Seeker

  • Active Members
  • 11 posts

Posted 17 August 2009 - 03:26 PM

I'm trying to use HotKey.au3 to use Win-L to lock the computer and run the screen saver based on a post from Lej.

After pressing Win-L the computer locks and the screen saver runs. The problem is after I unlock the computer the keyboard locks up until I hit a modifier key (shift, ctrl, alt, or win).

Try this to recreate:
  • Have Notepad open when running the script
  • Run the script
  • Press Win-L
  • Unlock the computer
  • Try typing in Notepad
  • Typing "l" the first time will allow all the alphanumeric keys to work. Typing "l' the second time will lock the computer without pressing the Win key.
#include "HotKey.au3" #include "vkConstants.au3" HotKeySet("{Esc}", "_Quit") _HotKeyAssign(BitOr($CK_WIN, $VK_L), "ScreenSaver") While 1     Sleep(10) WEnd Func ScreenSaver()     Local Const $SC_SCREENSAVE = 0xF140     DllCall('user32.dll', 'int', 'LockWorkStation')      _SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0) EndFunc   ;==>ScreenSaver Func _Quit()     Exit EndFunc   ;==>_Quit


The problem isn't specific to Win-L. The same thing happens when I change the script to use Win-K (hitting "k" the second time will lock the computer)

Any ideas on what I'm doing wrong?

--Jeff




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users