Please help with joystick wasd

Could someone please help me with coding a joystick to wasd. I have got wasd working but for the life of me i can not get diagonals to work currently. I have spent a week looking for a solution and can not find one.

Show your code to someone who knows what they're doing and see if they can help you find the issue.

who can i show it to? nobody where i live has any knowledge about coding.

rontonomo:
who can i show it to? nobody where i live has any knowledge about coding.

Really? You're here aren't you? How about the people on this forum? SMDH!

The point is that they can't help you if you don't show them what you want them to help with. Doesn't that make sense? Come on now? Coding is a thinking mans game. You gotta try a little harder than this.

rontonomo:
who can i show it to? nobody where i live has any knowledge about coding.

I think Reply #1 was a not-so-subtle hint to get you you to show your code to us.

Also what is "wasd"? is there a datasheet or a user-manual that you can post a link to?

...R

sorry keyboard keys wasd for using joystick in pubg game. here is the code i have so far thanks for the help.

void setup() {
Keyboard.begin();
}

void loop(){

int sensorValueX = analogRead(A11);
int sensorValueY = analogRead(A10);

if (sensorValueY < 20){
Keyboard.press(KEY_W);
delay(20);
Keyboard.release(KEY_W);
}

else if(sensorValueX < 20){
Keyboard.press(KEY_A);
delay(20);
Keyboard.release(KEY_A);
}

else if(sensorValueY > 1000){
Keyboard.press(KEY_S);
delay(20);
Keyboard.release(KEY_S);
}

else if(sensorValueX > 1000){
Keyboard.press(KEY_D);
delay(20);
Keyboard.release(KEY_D);
}

}

Please go read the "How to use this forum" thread so you can learn the posting guidelines and stop wasting everyone's time.

What type of Arduino do you have? Can you give us the rest of the details about the project. Please try to understand that none of us are there with you. We can only see what you decide to show us. How well you get helped depends entirely upon that. So the ball is in your court.

You talk about diagonals. Does that mean that multiple keys would be pressed at once? But your conditions are all "else if" so only one can run at any given time. Only the first one it comes to that is true gets run and the rest get skipped. That's what the "else" does.

Thank you for pointing out my mistakes. That is the only way to learn. I did not know any other way of trying this code because i am completely new to arduino. It took me a week to try and find the code searching the internet to try and make my joystick work. What i am trying to do is set up Just the joystick to work in a game using the keyboard keys w,a,s,d. I am sure you are right with me using else if causing the code to not work. Here is what i am working with. I have a teensy lc and a vellmon 2-axis joystick with a button, but nit using the button. I would like to be able to use the keyboard keys to move in an 8-way pattern, but as i said and you pointed out i can not get the diagonals to work with how i have it. All your help is greatly appreciated. Here is the code the proper way(i hope).

void setup() {
  Keyboard.begin();
   }

void loop(){

  int sensorValueX = analogRead(A11);
  int sensorValueY = analogRead(A10);

 if (sensorValueY < 20){
   Keyboard.press(KEY_W);
   delay(20);
   Keyboard.release(KEY_W); 
    }

   else if(sensorValueX < 20){
    Keyboard.press(KEY_A);
    delay(20);
    Keyboard.release(KEY_A);
     }

   else if(sensorValueY > 1000){
    Keyboard.press(KEY_S);
    delay(20);
    Keyboard.release(KEY_S);
     }
    
   else if(sensorValueX > 1000){
    Keyboard.press(KEY_D);
    delay(20);
    Keyboard.release(KEY_D);
     }
     
    }

OK. So we've decided that the "else" is causing only one to be evaluated at a time. So if you want more than one to be evaluated at a time...

Come on now, just think a little, you're almost there...

Well i took the else out of the code and it still no diagonal directions work. Im at a loss here, you seem to know how to fix it can you help me out?

What makes you think I know how to fix it? I barely know what the hell you’re trying to do. You’ve left out almost all the important details. You won’t answer the questions I’ve asked. Why should I waste anymore time here?

I have tried to give you all the info you have asked for. What do you need? What questions have i not answered? When you say things like come on now, just think a little, you’re almost there… it makes me think you know how to fix it.

I knew one really obvious thing to try. You say it doesn't work. I'm not really sure what that means. I don't have a lot of symptoms to work with here other than that it doesn't go diagonally. That might just be how your game works for all I know. Think if you can find a way to get the output of this program where someone could look at it. Do you have any programs on your computer that capture keystrokes in a human readable format? I'm betting you have a few.

Did you manage to figure this out? I wanted to map WASD to a joystick also and i copied your code (thx for that). I was able to get the diagonals working and some other little tweeks .

This Thread is nearly 2 years dead.

If you need help please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

Details of what Arduino board you are using and what you have connected to it will also help.

...R

Robin2:
This Thread is nearly 2 years dead.

If you need help please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

Details of what Arduino board you are using and what you have connected to it will also help.

...R

I wanted to see if the original poster was still knocking about.

Sorry for the late reply, been really busy with college, but anyways I did figure this out eventually. Here is the basic code for making a joystick work as WASD keys. The threshold limits may need to be tweaked as needed with your joystick, but they should be close enough to use.

In case anyone is not sure what this does, this is to make a joystick work as keyboard WASD keys so it can be used in PC games that do not allow joysticks and keyboard and mouse configurations to be used at the same time. The joystick instead sends the WASD keys allowing it to work in these games. Which in the end allows for custom macro pads with programmable joysticks to be used while gaming with your mouse. If you have any improvements please let me know.

//Mapping a Joystick to WASD Keyboard Keys

int currStateY1;
int prevStateY1;
int currStateY2;
int prevStateY2;
int currStateX1;
int prevStateX1;
int currStateX2;
int prevStateX2;

void setup()
{
  Keyboard.begin();
}

void loop()
{
  int sensorValueY = analogRead(A11);
  int sensorValueX = analogRead(A10);

  { // Y+
    currStateY1 = sensorValueY > 404;
    if (currStateY1 != prevStateY1)
    {
      if (currStateY1 == (sensorValueY < 50))
      {
        Keyboard.press(KEY_W);
      }
      else
      {
        Keyboard.release(KEY_W);
      }
    }
    prevStateY1 = currStateY1;
  }

  { //Y-
    currStateY2 = sensorValueY < 594;
    if (currStateY2 != prevStateY2)
    {
      if (currStateY2 == (sensorValueY > 973))
      {
        Keyboard.press(KEY_S);
      }
      else
      {
        Keyboard.release(KEY_S);
      }
    }
    prevStateY2 = currStateY2;
  }

  { //X
    currStateX1 = sensorValueX > 408;
    if (currStateX1 != prevStateX1)
    {
      if (currStateX1 == (sensorValueX < 50))
      {
        Keyboard.press(KEY_A);
      }
      else
      {
        Keyboard.release(KEY_A);
      }
    }
    prevStateX1 = currStateX1;
  }

  { //X-
    currStateX2 = sensorValueX < 598;
    if (currStateX2 != prevStateX2)
    {
      if (currStateX2 == (sensorValueX > 973))
      {
        Keyboard.press(KEY_D);
      }
      else
      {
        Keyboard.release(KEY_D);
      }
    }
    prevStateX2 = currStateX2;
  }
}