How to get around the key auto-repeat that kicks in after 1 sec
-
To be able to play a note by the USB-keyboard, I need to detect if a key is pressed and also how long. For this I use
key = getKeyboardBuffer()
.showKeyboard() loop key = getKeyboardBuffer() print( key ) update() repeat
The problem is: if I press the a-key, it prints an "a", then stops for 1 s and then it continuously prints "a"'s. So, between "pressing the key" I don't know for the duration of 1 sec, if the key is still pressed or not.
output, when pressing the a-key:
a
after one second
aa
and then the "a" gets continuously added every 1 ms
aaaaaaaaaa->
Does this mean its not possible to create a keyboard controlled piano, that is able to control the sound between ~1 ms and 1 s? Any suggestions are appreciated.
-
@spikey I hadn't noticed that before. It looks like the keyboard has a built in "debounce" delay to stop unintentional auto repeat. There doesn't seem to be a way of changing or turning this off at the moment.
-
Thank you for your comment. I was checking other keyboards, its either a default of the USB keyboards, or its from the switch OS, keyboard driver (I a guess, because on Windows I think one can adjust it). In the Switch-System-Settings, I could not found anything like this.
I will try to use it how it is, it takes 29 frames, afterwards the key is repeated every 6 frames.
I checked how this works in Korg Gadget (you can play sounds there using the USB keyboard as well). They seem to have found a way to do it. But understand me right, I did not write this as a bug report or change suggestion. Most probably nobody else will try to do anything with the key auto-repeat ever.😉 -
I found a workaround, not sure how solid it will be for the project behind:
a) during the first 29 frames I process any character coming from the key buffer, I enter the status "KEY_PRESS" and "KEY_DOWN"
b) after 30 frames I check if the key-character is in the buffer, so I keep the status "KEY_DOWN" if its not in the buffer we are in the state "KEY_RELEASED"
c) after 30 frames I check every 7th frame if the character is in the key buffer and stay in "KEY_DOWN" status or if not change to "KEY_RELEASED"
Example over here: https://fuzearena.com/forum/topic/947/re-use-sounds-from-the-soundfx-generator-with-the-usb-keyboard