AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

lose delay from setTime / KeyWait with GetKeyState? [SOLVED]

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
deandoe



Joined: 01 Oct 2008
Posts: 11

PostPosted: Mon Oct 13, 2008 12:28 pm    Post subject: lose delay from setTime / KeyWait with GetKeyState? [SOLVED] Reply with quote

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
View user's profile Send private message
deandoe



Joined: 01 Oct 2008
Posts: 11

PostPosted: Tue Oct 14, 2008 10:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Wed Oct 15, 2008 1:36 am    Post subject: Reply with quote

Code:
$n::
Sleep 250
If GetKeyState("n", "p")
   Run Notepad.exe
Else Send {Blind}n
return

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!
Back to top
View user's profile Send private message
deandoe



Joined: 01 Oct 2008
Posts: 11

PostPosted: Wed Oct 15, 2008 9:38 am    Post subject: Reply with quote

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
View user's profile Send private message
deandoe



Joined: 01 Oct 2008
Posts: 11

PostPosted: Wed Oct 15, 2008 10:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
totalmig



Joined: 22 Jul 2008
Posts: 151

PostPosted: Thu Oct 16, 2008 1:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1271

PostPosted: Tue Oct 21, 2008 5:13 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
totalmig



Joined: 22 Jul 2008
Posts: 151

PostPosted: Tue Oct 21, 2008 8:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1271

PostPosted: Tue Oct 21, 2008 10:42 pm    Post subject: Reply with quote

I noticed this delay too.
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
totalmig



Joined: 22 Jul 2008
Posts: 151

PostPosted: Wed Oct 22, 2008 1:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group