I’m having an issue that was not a problem with Carbon:
In the case where a user “sits” on a key, and I want to clear or ignore queued keydown events (which stack up when user holds a key down). I can’t figure how to clear the buffer, i.e. ignore stacked up repeats.
It’s probably something simple, but I’m not seeing it.
What control are you experiencing this in?
Window.keydown event
Function KeyDown(Key As String) As Boolean
static oldkey as string
static oldticks as integer = ticks
if oldkey = key and ticks-oldticks<60 then
oldkey = key
return true
end if
oldkey = key
oldticks = ticks
End Function
Now if the user holds the key, it will fire again only after one second. You can reduce the value in ticks-oldticks<60
. A tick is 1/60th a second.
Thanks! Trying this soon…
Note that as of 10.8 (?) many repeated key presses don’t generate the same events, instead it brings up the key picker for alternatives, such as A etc.
Just checked. With a one second delay, the selection box appears fine in a Text entry control. For a multilingual app, maybe reducing the delay to half a second would be necessary to accelerate the appearance of the box.
For non text controls, no need.
Michael,
How could you implement this when using Keyboard.AsyncKeyDown?
I am forced in my current app progress to use this method instead of a regular KeyDown event.
THX
JMW
[quote=122257:@Michel Bujardet]Function KeyDown(Key As String) As Boolean
static oldkey as string
static oldticks as integer = ticks
if oldkey = key and ticks-oldticks<60 then
oldkey = key
return true
end if
oldkey = key
oldticks = ticks
End Function
Now if the user holds the key, it will fire again only after one second. You can reduce the value in ticks-oldticks<60
. A tick is 1/60th a second.[/quote]