Right now I have the arrow keys programmed into my keybow. Unfortunately, when I press and hold one of the arrow keys the cursor (or web page, if I’m scrolling) doesn’t keep moving like it would on your typical keyboard, instead my cursor stays in place so if I want to keep things moving along I have to repeatedly press the key. What do I need to change to get this to work?
I’m using the arrow keycodes like this: keyboard.send(Keycode.LEFT_ARROW)
Conceptually, you’d probably want to listen for a key-down, and then start a timer. If the corresponding key-up doesn’t come within a certain period (the autorepeat delay), then start sending the same keypress again periodically at a given interval (the autorepeat interval or frequency), until the corresponding key up comes.
Bear in mind that the key-down and key-up events for different keys may be interleaved. That’s one of the many reasons why keyboard firmware is complex!
depending on how you have things set up you can do the following
# some code to detect when you first press the button
keyboard.press( Keycode.LEFT_ARROW )
# some code to detect when you first release the button
keyboard.release( Keycode.LEFT_ARROW )
this method lets the receiving device decide how long to wait before repeating, and how fast to repeat (or whether to repeat at all). that’s how commercial keyboards do it.
# code that detects if the key is currently pressed regardless
keyboard.send( Keycode.LEFT_ARROW )
# send is the same as press + release all at once
the second method is much easier, but may behave differently than you expect, because the timing of repeats is completely under your control.
I don’t have the old shipped examples, but I believe they might be similar enough… the “advanced” example should auto repeat, but the “simple” & “decorators” examples may not unless you tweak them. there should be a line in those that looks like
add a new line below it at the same indent level
don’t know why, but the current examples don’t include hold (despite using .send), so would block held keys from firing more than once per press.
You could alternatively change the example to use .press and .release, but I recommend reading this first