AutoHotkey Community

It is currently May 27th, 2012, 5:25 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: October 18th, 2010, 12:08 am 
Offline

Joined: April 9th, 2008, 8:46 am
Posts: 35
Location: Espoo, Finland
I can't believe such simple functionality would be missing from ahk, but I couldn't find this in the help file or forum search:

How to make a hotkey subroutine run only on a real keypress, not on ones generated by key repeat (typematic)? Using a state variable for each such hotkey would be just inelegant and redundant as the WM_KEYDOWN message already contains repeat count and previous state bits.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2010, 12:16 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Something like this?
Code:
$a::
  Send, a
  KeyWait, a
Return

or
Code:
Loop, 26
  HotKey, % "$" Chr(A_Index+96), myLabel
Return

myLabel:
  Send, % SubStr(A_ThisHotkey,2)
  KeyWait, % SubStr(A_ThisHotkey,2)
Return

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2010, 12:28 am 
Offline

Joined: April 9th, 2008, 8:46 am
Posts: 35
Location: Espoo, Finland
Ah, true, the KeyWait function is likely sufficient for my needs, :) but that's still a workaround; i.e. based on suspending threads and still discarding the keyrepeat status bits. Your example would still activate if I start the script in the middle of holding down 'a'. :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2011, 9:42 pm 
Offline

Joined: April 9th, 2008, 8:46 am
Posts: 35
Location: Espoo, Finland
Actually, the keywait method is seriously flawed, since AHK is essentially single threaded.

Consider for instance the following:
Code:
$*a::
Send, {blind}{a down}
KeyWait, a
Send, {a up}
return

$*s::
Send, {blind}{s down}
KeyWait, s
Send, {s up}
return

It's supposed to disable typematic for a and s keys. Simple enough? But it fails when using the keys simultaneously. E.g. pressing
a down, s down, a up
should trigger the "Keywait, a", but there's actually only a single thread waiting on the "KeyWait, s". Therefore, tapping a while holding s does nothing!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2011, 10:50 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
You can use GetKeyState.
Code:
$*a::
If !GetKeyState("a") ;if "a" is not down
 Send, {blind}{a down}
Return

*a Up::
Send, {a up}
return

$*s::
If !GetKeyState("s")
 Send, {blind}{s down}
Return

*s Up::
Send, {s up}
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2011, 1:13 am 
Offline

Joined: April 9th, 2008, 8:46 am
Posts: 35
Location: Espoo, Finland
Sorry, I guess my post was slightly misleading. Basically I want to disable typematic for hotkeys with arbitrary functionality, not just simple key down/up ones. I.e.
Code:
*key1::
If (keypress is from typematic)
   return
Myfunction1()
return


So is the following combination really the only way to accomplish this?
Code:
*key1::
If (hotkey1_active)
   return
hotkey1_active := 1
Myfunction1()
return

*key1 up::
hotkey1_active := 0
return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], HotkeyStick, rbrtryn, XstatyK, Yahoo [Bot] and 80 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group