Jump to content
Sign in to follow this  
Sven

How to block a hotkey from being sent to the application unless being sent by the script's function?

Recommended Posts

Sven

Hello,

don't know if this has been answered before, but I couldn't find anything via the search function. Here we go:

For the game I'm currently playing, I need some stuff (cursor up) done before the ingame-function (F2 key) is being executed. For ease of use, I've assigned the same key (F2) to my script as the hotkey. However, as soon as I hit the F2 key, the ingame-function is started without the execution of what should be done before this by the script.

My question now is, how can I prevent the hotkey from being sent to the application I'm trying to control until it is triggered by the script?

hotkeyset("{f2}", "myfunc")

while 1
    sleep(100)
wend

func myfunc()
    send ("{up}")
    send ("{f2}")
    wend
endfunc

Thank you for your help.

Edited by Sven

Share this post


Link to post
Share on other sites
SmOke_N

This seemed to be able to tell the difference between the script sending it, and or it being manually pressed if that was what you were looking for:

#include <Misc.au3>; Beta .126 is being used here
HotKeySet('{F2}', 'F2')

Global $Timer = TimerInit()
While 1
    Sleep(1000)
    If TimerDiff($Timer) / 1000 >= 3 Then
        Send('{F2}')
        $Timer = TimerInit()
    EndIf
WEnd

Func F2()
    If Not _IsPressed('71') Then
        MsgBox(0,'Info:', 'Script Sent')
        $Timer = TimerInit()
    Else
        MsgBox(0,'Info:', 'Manually Pressed')
        $Timer = TimerInit()
    EndIf
EndFunc


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Sven

I finally got it to work. Thanks for showing me the right direction :D .

Edited by Sven

Share this post


Link to post
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
Sign in to follow this  

×