| View previous topic :: View next topic |
| Author |
Message |
deandoe
Joined: 01 Oct 2008 Posts: 11
|
Posted: Mon Oct 13, 2008 12:28 pm Post subject: lose delay from setTime / KeyWait with GetKeyState? [SOLVED] |
|
|
based on my previous posts i figured out that both the constructions SetTimer and KeyWait for performing different actions when pressing 1 button once (maintain original function, typing the letter r) or twice (call function x) brings a significant delay. (when typing words involving r the effect is that the letter after the r comes for the r: wolrd). the solution for the problem is to assign different actions to different keys. but that makes things just more complicated, so actually it's not a solution for me.
i thought a solution might be to record the time one key is pressed down. that would fix the delay problem when typing words.
| Code: | GetKeyState, state, r
if state = D > 200 (ms)
action 1
else
send, r |
Maybe some can reflect on my point of view and help me if possible, thanks
| Code: | Current situation (which always gives the Delay (in ms) when typing):
if keyPressed, KeyPressedAgain < Delay
action 1
else
send, r
|
Last edited by deandoe on Wed Oct 15, 2008 10:12 pm; edited 1 time in total |
|
| Back to top |
|
 |
deandoe
Joined: 01 Oct 2008 Posts: 11
|
Posted: Tue Oct 14, 2008 10:16 pm Post subject: |
|
|
i'm not giving up and still try to make things work. since my programming experience is not that great i hope someone could tell me if it's even possible to perform an action like this. or that i'm trying to do the impossible. thanks anyway.
| Code: | GetKeyState, state, r ;define the button which will be watched
if state = D > 200 (ms) ;if the button gets pressed longer then 200 ms
action 1 ;execute action 1 (e.g. run notepad)
else ;else...
send, r ;...keep the original function (enter gives an enter, r gives an r) |
|
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
|
| Back to top |
|
 |
deandoe
Joined: 01 Oct 2008 Posts: 11
|
Posted: Wed Oct 15, 2008 9:38 am Post subject: |
|
|
thnx, so may i conclude that the answer to the topic question is no? every function (setTime, KeyWait, GetKeyState) created has it's delay at the beginning of the script; there will be always a, no matter how short, a delay? when typing all functions fail, no becomes on..
so the proposed function is not possible?
| Code: | as soon as the key gets pressed
timer starts
if the key is pressed longer then 500ms
fuction a will execte
else keep original function |
in the case above, typing is no problem since one keystroke will always be shorter then 500 ms only when i hold the key down long enough the function will execute..
thanks anyway for the help and suggestion you did. |
|
| Back to top |
|
 |
deandoe
Joined: 01 Oct 2008 Posts: 11
|
Posted: Wed Oct 15, 2008 10:10 pm Post subject: |
|
|
the solution is the usage of: A_TimeSinceThisHotkey thanks to laz0r in the irc channel #ahk =)
| Code: | $r::
KeyWait r
If A_TimeSinceThisHotkey > 200
Send a
Else
Send r
Return |
this function will always type an r (as rapid as writing other characters) when typing in a word processor but will execute a function when holding down the key for more then 200 ms. thanks anyway for all the support!
Last edited by deandoe on Tue Nov 25, 2008 6:03 pm; edited 1 time in total |
|
| Back to top |
|
 |
totalmig
Joined: 22 Jul 2008 Posts: 151
|
Posted: Thu Oct 16, 2008 1:51 pm Post subject: |
|
|
Thanks. found this very usefull.
One thing i noticed was that it won't be send until you actually release R. So if you hold R for 2mins, nothing happens. Any way to do it so it triggers as soon as you hit the 200ms ? |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Tue Oct 21, 2008 5:13 pm Post subject: |
|
|
Use the timeout option:
| Code: | $r::
KeyWait r, T0.2
If A_TimeSinceThisHotkey > 200
Send {a}
Else
Send {r}
Return |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
totalmig
Joined: 22 Jul 2008 Posts: 151
|
Posted: Tue Oct 21, 2008 8:29 pm Post subject: |
|
|
Ahh great idea, had thought of another way of doing it, but was abit more complex.
I've tried adding hotkeys like this to alot of the keyboard buttons, but it seems like its still causing a very very small delay (which i'm think is inevitable?). The odd thing is that even i have hotkeys on all the letters i'm trying to use, it the still come out in a different order.
For example, lets say i have hotkeys on p, o, w, e and r. And if i type power fast, i'lll end up with opewr, poewr etc. Seems odd to me that i'm getting different delay on the same code? |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Tue Oct 21, 2008 10:42 pm Post subject: |
|
|
I noticed this delay too. _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
totalmig
Joined: 22 Jul 2008 Posts: 151
|
Posted: Wed Oct 22, 2008 1:55 pm Post subject: |
|
|
| Good to hear. What really got me wondering is how two hotkeys with the exact same code, can take different time to execute. |
|
| Back to top |
|
 |
|