Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Background:

Joystick - Razor Ruiji Master

Visual Studio 2019

Windows Form in C#

I'm trying to figure out how to make a physical joystick button press, press a button on the windows form UI in Visual studio using C#.

Code of Physical joystick:

C#
private void joystickTimer_Tick_1(object sender, EventArgs e)
    {
        try
        {
            joystick.UpdateStatus();
            joystickButtons = joystick.buttons;

            if (joystick.Xaxis == 0)
                output.Text+="Left\n";

            if (joystick.Xaxis == 65534)
                output.Text+="Right\n";

            if (joystick.Yaxis == 0)
                output.Text+="Up\n";
            
            if (joystick.Yaxis == 65535)
                output.Text+="Down\n";

            

            for (int i = 0; i < joystickButtons.Length; i++)
            {
                // Assigning buttons
                if (joystickButtons[0] == true)
                    output.Text += "Cross\n";
                

                else if(joystickButtons[1] == true)
                    output.Text += "Circle\n";

                else if(joystickButtons[2] == true)
                    output.Text += "Square\n";


                else if (joystickButtons[3] == true)
                    output.Text += "Triangle\n";
                    Btn_Emergency_Stop_Click(sender,e); //Attempt at button press
                    break;
            }
        }
        catch
        {
            joystickTimer.Enabled = false;
            connectToJoystick(joystick);
        }
    }

Virtual button to be pressed:

C#
private void Btn_Emergency_Stop_Click(object sender, EventArgs e)
    {

    }

If there is any information I've missed out in providing please notify me.

What I have tried:

I've tried, using
Btn_Emergency_Stop_Click(null,null);
or
Btn_Emergency_Stop_Click(sender,e); 
or
C#
Btn_Emergency_Stop_Click.Click += joystickButtons[3];
Not sure If I'm on the right track any help will be appreciated!

Thank You!
Posted
Updated 13-Jan-21 23:59pm
v2

1 solution

 
Share this answer
 
Comments
User-15002776 14-Jan-21 20:44pm    
Hey RickZeeland, I've taken a look at the library that you suggested, there doesn't seem to be any tutorial, however I"ve downloaded the demo file and installed the setup exe and I've connected the joystick to the exe program showing all the outputs. Are there any quick pointers on how to use this library? I'm assuming I just need to import the library with (using Hid = SharpLib.Hid;) at the top of my form1.cs file. And to assign the buttons I need to use something with WM_INPUT. Thank You!
RickZeeland 15-Jan-21 1:33am    
Sorry, I never used this library myself, just found it on Google ...
User-15002776 17-Jan-21 20:43pm    
Oh.... xD

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900