Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 2.0 Two keystrokes if button is pressed

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    2

    Teensy 2.0 Two keystrokes if button is pressed

    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);}

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,910
    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_timin...pedMillis.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.

  3. #3
    Junior Member
    Join Date
    Nov 2019
    Posts
    2
    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();}}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •