Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace csJoy
- {
- public partial class Form1 : Form
- {
- public struct JOYINFOEX
- {
- public Int32 dwSize; /* size of structure */
- public Int32 dwFlags; /* flags to indicate what to return */
- public Int32 dwXpos; /* x position */
- public Int32 dwYpos; /* y position */
- public Int32 dwZpos; /* z position */
- public Int32 dwRpos; /* rudder/4th axis position */
- public Int32 dwUpos; /* 5th axis position */
- public Int32 dwVpos; /* 6th axis position */
- public Int32 dwButtons; /* button states */
- public Int32 dwButtonNumber; /* current button number pressed */
- public Int32 dwPOV; /* point of view state */
- public Int32 dwReserved1; /* reserved for communication between winmm & driver */
- public Int32 dwReserved2; /* reserved for future expansion */
- }
- JOYINFOEX joystickInfo;
- [System.Runtime.InteropServices.DllImport("winmm.dll", CallingConvention = CallingConvention.StdCall)]
- public static extern UInt32 joyGetPosEx( UInt32 uJoyID, ref JOYINFOEX pji );
- public Form1()
- {
- InitializeComponent();
- joystickInfo.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(joystickInfo);
- joystickInfo.dwFlags = 0xFFFF;
- UInt32 joyRes = joyGetPosEx( 0, ref joystickInfo);
- int jjj = 0;
- }
- private void onTimer(object sender, EventArgs e)
- {
- joystickInfo.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(joystickInfo);
- joystickInfo.dwFlags = 0xFFFF;
- UInt32 joyRes = joyGetPosEx(0, ref joystickInfo);
- this.Invalidate();
- }
- private void onPaint(object sender, PaintEventArgs e)
- {
- Graphics gr = e.Graphics;
- string str = String.Format( "X Y Z: {0} {1} {2} ",
- joystickInfo.dwXpos,
- joystickInfo.dwYpos,
- joystickInfo.dwZpos);
- gr.DrawString(str, SystemFonts.CaptionFont, Brushes.Black, 10, 10);
- //dc.TextOut(10, 10, str);
- /*str.Format(L"R U V: %04X %04X %04X ",
- joystickInfo.dwRpos,
- joystickInfo.dwUpos,
- joystickInfo.dwVpos);
- dc.TextOut(10, 30, str);
- str.Format(L"P B N: %04X %04X %04X ",
- joystickInfo.dwPOV,
- joystickInfo.dwButtons,
- joystickInfo.dwButtonNumber);
- dc.TextOut(10, 50, str);*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement