Sign in to follow this  
Followers 0
Dryden

Interrupting a Hotkey or reading _IsPressed only one time

9 posts in this topic

Hi again.

I have a script that uses 5 hotkeys, but the problem is that some of them need to be sent back with send(), the problem is that when i have a hotkey, if i send it back the script enters in an endless loop. and if i use _IsPressed then the key is sent back only once (the time that it was pressed) but the function gets executed too many times (i think it doesn't get executed once but again and again until the key is released).

So what I'm looking for is either for a way to ignore a Hotkey while sending the same key or a way to run my funclion only once when i press the key once using _IsPressed

thx


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites



Hi again.

I have a script that uses 5 hotkeys, but the problem is that some of them need to be sent back with send(), the problem is that when i have a hotkey, if i send it back the script enters in an endless loop. and if i use _IsPressed then the key is sent back only once (the time that it was pressed) but the function gets executed too many times (i think it doesn't get executed once but again and again until the key is released).

So what I'm looking for is either for a way to ignore a Hotkey while sending the same key or a way to run my funclion only once when i press the key once using _IsPressed

thx

Use HotKeySet("KEY") without function parameter.

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Use HotKeySet("KEY") without function parameter.

I don't get it...

without function parameter how is my function going to be called?


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

I think that maybe I'm not explaining myself properly:

Imagine this:

I have a hotkey that is H

and when the user presses that hotkey I want my program to send it ant then do a couple of commands that i have set in a function.

the problem is that if i send H my script goes berzek, cos i'm sending H and he has a hotkey that it's the same and detects it's own send as a hotkey itself...

so in another approach i tried to use _IsPressed. knowing that H is #48 key, i used ispressed so whenever the script detected that key #48 is pressed it would run my function, but the I got another problem... The function runs over and over again cos _ispressed run again and again until the key is released, and I want the function to run only once every time u press H.


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

If I understood correctly you want to send the same char like you key from hotkey:

HotKeySet("M","SendText")

Func SendText()
    HotKeySet("M")
    Send("My text")
    HotKeySet("M","SendText")
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites

i think he wants something like this:

HotKeySet("M","SendText")
global $var = 0

Func SendText()

If $var = 0 then
    HotKeySet("M")
    Send("My text")
    HotKeySet("M","SendText")
$var = 1
EndIf

EndFunc

Crude, but the hotkey will only trigger once.

Share this post


Link to post
Share on other sites

Alternatively, if you want the hotkey to continue working more than one time, add a sleep(200) before the function is run. It should be enough time for the key to release.

Share this post


Link to post
Share on other sites

hum... this might work. thx guys. gona try this as soon I get home.


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites

yep, it works! thx m8s :)


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

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  
Followers 0