Is there a Keyboard.write code to hold down a key?

Hello all

I have posted related topics in the past but for anyone who wants to know I am coding a game controller using an Arduino Leonardo. It works pretty well. I have 4 buttons and a joystick. What I do is I have the buttons and joysticks coded to Keyboard.write a specific key such as w, a, s, d.

My problem is that for my joystick, instead of having a button to hold down a key, it just presses the key over and over again. For example, when I hold left on the joystick, it presses the same key over and over again instead of holding it down. This is a problem because my characters in game go at half the speed as they always move a little and then stop over and over again.

I guess what my question is, is that is there a command like Keyboard.write that holds down the key instead of pressing it once?

Thanks in advance

For example, when I hold left on the joystick, it presses the same key over and over again instead of holding it down

You need to detect when the joystick [u]becomes[/u] pushed in a direction rather than when it [u]is[/u] in a direction. Look at the StateChangeDetction example in the IDE

Thank you, this is good progress.

However, I am unsure what StateChangeDetection is and how I use it. It this a command I can use? If so, how does it work and how do I use it?

Squidnugget65: However, I am unsure what StateChangeDetection is and how I use it.

It's in the example sketch tab in the IDE File menu.

I am unsure what StateChangeDetection is

Look at the StateChangeDetction example in the IDE

read the joystick input as the current direction if the current direction is not equal to the previous direction then the joystick has moved if the joystick is now left do whatever you need when the joystick is left end if save the current direction as the previous direction ready to test again next time end if

(deleted)

UKHeliBob: read the joystick input as the current direction if the current direction is not equal to the previous direction then the joystick has moved if the joystick is now left do whatever you need when the joystick is left end if save the current direction as the previous direction ready to test again next time end if

Ok awesome, thanks for the help.