Jump to content

Recommended Posts

Posted

But it works if i use:

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

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

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
Posted

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

Posted (edited)

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
Posted (edited)

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
Posted (edited)

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
UnderWorldVN- Just play the way you like it
Posted

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.

#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

HotKey_17_beta.au3

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.

Posted

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 :)

Posted

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.

:)

Posted

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

Posted

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?
  • 1 month later...
Posted

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?

Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...