资源简介

c# DirectX DirectInput 游戏手柄 游戏摇杆 winform程序 项目想要用游戏摇杆控制无人车,用莱仕达的雷霆PRO做实验。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Management;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;

namespace RunJoyStickOnLocalMachine
{
    public partial class Form1 : Form
    {
        private Joystick joystick;
        private bool[] joystickButtons;
        private bool isCalibration = false;
        public struct CaliValue
        {
            public int xMin;
            public int xMax;
            public int yMin;
            public int yMax;
            public int xCenter;
            public int yCenter;
            public int leftThreshold;
            public int rightThreshold;
            public int upThreshold;
            public int downThreshold;
        }
        CaliValue caliValue;
        Point[] ps = new Point[] { new Point(2 0) new Point(2 1) new Point(0 2) new Point(1 2) new Point(3 2) new Point(4 2) new Point(2 3) new Point(2 4) };
        //十字大bai小
        int sizeP = 1;
        //十字的位置
        Point pos = new Point(0 0);
        private void SetPos(int x int y)
        {
            pos.X = x - sizeP * 2;
            pos.Y = y - sizeP * 2;
        }
        public Form1()
        {
            InitializeComponent();
            joystick = new Joystick(this.Handle);
            connectToJoystick(joystick);
        }

        private void Form1_Load(object sender EventArgs e)
        {

        }

        //---------------------------------------------------------------------
         private void connectToJoystick(Joystick joystick)
        {
            while (true)
            {
                string sticks = joystick.FindJoysticks();
                if (sticks != null)
                {
                    if (joystick.AcquireJoystick(sticks))
                    {
                        enableTimer();
                        break;
                    }
                }
            }
        }

        private void enableTimer()
        {
            if (this.InvokeRequired)
            {
                BeginInvoke(new ThreadStart(delegate()
                {
                    joystickTimer.Enabled = true;
                }));
            }
            else
                joystickTimer.Enabled = true;
        }

        private void joystickTimer_Tick_1(object sender EventArgs e)
        {
            try
            {
                Graphics g = pictureBox1.CreateGraphics();
                g.Clear(Color.White);

                //获取xyz坐标
                joystick.UpdateStatus();
                joystickButtons = joystick.buttons;
                output.Text = “ x: “+ joystick.Xaxis.ToString()+“\n“;
                output.Text += “ y: “ + joystick.Yaxis.ToString() + “\n“;
                

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-06-07 15:33  RunJoyStickOnLocalMachine\
     目录           0  2020-06-07 15:33  RunJoyStickOnLocalMachine\.vs\
     目录           0  2020-06-07 15:33  RunJoyStickOnLocalMachine\.vs\RunJoyStickOnLocalMachine\
     目录           0  2020-06-07 15:33  RunJoyStickOnLocalMachine\.vs\RunJoyStickOnLocalMachine\v14\
     文件       57856  2020-06-07 17:46  RunJoyStickOnLocalMachine\.vs\RunJoyStickOnLocalMachine\v14\.suo
     目录           0  2020-06-07 17:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\
     文件         917  2014-11-18 19:23  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine.sln
     文件       33280  2014-12-06 03:11  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine.suo
     文件         219  2020-06-07 15:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\App.config
     目录           0  2014-12-06 03:18  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\
     目录           0  2020-06-07 15:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\
     文件      159232  2005-03-18 16:23  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\Microsoft.DirectX.DirectInput.dll
     文件      345509  2006-03-07 22:46  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\Microsoft.DirectX.DirectInput.xml
     文件      223232  2005-03-18 16:23  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\Microsoft.DirectX.dll
     文件      265390  2006-03-07 22:46  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\Microsoft.DirectX.xml
     文件       15872  2020-06-07 17:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\RunJoyStickOnLocalMachine.exe
     文件         219  2020-06-07 15:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\RunJoyStickOnLocalMachine.exe.config
     文件       30208  2020-06-07 17:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\RunJoyStickOnLocalMachine.pdb
     文件       22696  2020-06-07 17:46  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\RunJoyStickOnLocalMachine.vshost.exe
     文件         219  2020-06-07 15:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\RunJoyStickOnLocalMachine.vshost.exe.config
     文件         490  2018-02-19 20:12  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\bin\Debug\RunJoyStickOnLocalMachine.vshost.exe.manifest
     文件        6542  2020-06-07 17:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\Form1.cs
     文件        8258  2020-06-07 17:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\Form1.Designer.cs
     文件        6018  2020-06-07 17:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\Form1.resx
     文件        4130  2020-06-07 16:53  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\Joystick.cs
     目录           0  2020-06-07 15:33  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\obj\
     目录           0  2020-06-07 15:33  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\obj\x86\
     目录           0  2020-06-07 17:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\obj\x86\Debug\
     文件        3442  2020-06-07 15:43  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7360  2020-06-07 17:42  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件        1577  2020-06-07 17:46  RunJoyStickOnLocalMachine\RunJoyStickOnLocalMachine\obj\x86\Debug\RunJoyStickOnLocalMachine.csproj.FileListAbsolute.txt
............此处省略20个文件信息

评论

共有 条评论