Teensy 2.0 Two keystrokes if button is pressed

Status
Not open for further replies.

kevin92

New member
Hello,

i am trying to have the F7 key pressed twice, thrice etc, if Pin 20 goes low. What is the best way to go about this? I have tried to just copy the Keyboard.press() part to repeat it, but that doesn't work.

F7 is used for Volume down in an application and 1 step at a time is too low of a resolution for a range of 100.

Code:
if (digitalRead(20) == LOW)
{Keyboard.press(KEY_F7);}
else{ Keyboard.release(KEY_F7);}
 
The simple option is to delay(50) or similar and then release, short delay before checking if digital read is still low. Exact timings will depend on the USB bus handler at your computer. This will prevent other buttons from working, If you want to get clever about it you need to use millis() or https://www.pjrc.com/teensy/td_timing_elaspedMillis.html to count out say 5 keypresses while still working with other keys but it sounds like stopping while volume gets changed will work for you.
 
Hi, thanks for the input. I was playing around a little and got it to work with a loop on a rotary encoder. Here is an exerpt of the code:

Code:
    if(digitalRead(PinButton8) == HIGH){    
    for (int i = 0; i < 4; i++){
    Keyboard.set_modifier(0);
    Keyboard.set_key1(KEY_F7);
    Keyboard.send_now();
    Keyboard.set_key1(0);
    Keyboard.send_now();}}
 
Status
Not open for further replies.
Back
Top