G2A Many GEOs
SHARE
TWEET

Reddit Keyboard Arduino code

jangxx Mar 12th, 2020 503 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Keyboard.h>
  2.  
  3. uint8_t button_val[5];
  4. bool down[5];
  5. bool press_next[5];
  6.  
  7. uint8_t button_pins[5] = { 2, 3, 4, 5, 6 };
  8. char button_keys[5] = { 'j', 'k', 'a', 'z', 'x' };
  9.  
  10. void setup()
  11. {
  12.     for(uint8_t i = 0; i < 5; i++) {
  13.         pinMode(button_pins[i], INPUT_PULLUP);
  14.     }
  15.  
  16.     Keyboard.begin();
  17. }
  18.  
  19. void loop()
  20. {
  21.     for(uint8_t i = 0; i < 5; i++) {
  22.         button_val[i] = digitalRead(button_pins[i]);
  23.         press_next[i] = false;
  24.  
  25.         if (button_val[i] == 0 && !down[i]) {
  26.             down[i] = true;
  27.             press_next[i] = true;
  28.         } else if (button_val[i] == 1 && down[i]) {
  29.             down[i] = false;
  30.         }
  31.     }
  32.    
  33.     for(uint8_t i = 0; i < 5; i++) {
  34.         if (press_next[i]) {
  35.             Keyboard.press(button_keys[i]);        
  36.         }
  37.     }
  38.    
  39.     delay(50);
  40.  
  41.     for(uint8_t i = 0; i < 5; i++) {
  42.         if (press_next[i]) {
  43.             Keyboard.release(button_keys[i]);          
  44.         }
  45.     }
  46.  
  47.     delay(10);
  48. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top