# Keyboard.h, holding down keys

**URL:** <https://forum.arduino.cc/t/keyboard-h-holding-down-keys/1212899>\
**Category:** Programming\
**Created:** [January 18, 2024, 10:23pm UTC](https://forum.arduino.cc/t/keyboard-h-holding-down-keys/1212899 "2024-01-18T22:23:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thejoshbaker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/thejoshbaker/32/1035384_2.png) [@thejoshbaker](https://forum.arduino.cc/u/thejoshbaker)\
**Post date:** [January 18, 2024, 10:23pm UTC](https://forum.arduino.cc/t/keyboard-h-holding-down-keys/1212899/1 "2024-01-18T22:23:24Z")

</div>

I had a question regarding how to hold down keys in Ardunio, here is my code so far:

```arduino
#include <Keyboard.h>

#define LJX_PIN A0 
#define LJY_PIN A1 

int LJX_VAL;
int LJY_VAL;

void setup() {

  // STARTS
  Serial.begin(9600);
  Keyboard.begin();
}

void loop() {
  LJX_VAL = analogRead(LJX_PIN);
  LJY_VAL = analogRead(LJY_PIN);

  // HOLDS DOWN NO REPRECUSION

  if (LJX_VAL >= 1000){
    Keyboard.write('w');
  }
  if (LJX_VAL <= 100){
    Keyboard.write('s');
  }
  if (LJY_VAL >= 1000){
    Keyboard.write('d');
  }
  if (LJY_VAL <= 100){
    Keyboard.write('a');
  }
}

```

I have a joystick with the hookups displayed in the code. When holding left the keyboard repeatedly presses 'a' instead of just holding it. Also I know that there is no release on the keyboard, that is just because I was testing multiple things. I was wondering if there is any way to adjust my code to make the 'a' key get held down or if there is another library that can do the same thing?

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [January 19, 2024, 12:50am UTC](https://forum.arduino.cc/t/keyboard-h-holding-down-keys/1212899/2 "2024-01-19T00:50:15Z")

</div>

Can you tell us what you think should happen if the 'a' key is held down? Unless you tell us that there is noting needed to be done with your code.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 17, 2024, 12:50am UTC](https://forum.arduino.cc/t/keyboard-h-holding-down-keys/1212899/3 "2024-07-17T00:50:26Z")

</div>

Closed on July 17, 2024, 12:50am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
