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.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Security;
- namespace Lab8
- {
- public partial class Form1 : Form
- {
- [StructLayout(LayoutKind.Sequential)]
- public struct JOYINFO{
- public Int32 wXpos; /* x position */
- public Int32 wYpos; /* y position */
- public Int32 wZpos; /* z position */
- public Int32 wButtons; /* button states */
- };
- [StructLayout( LayoutKind.Sequential ) ]
- 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 mJoystickEx;
- JOYINFO mJoystick;
- [DllImport( "winmm.dll", CallingConvention = CallingConvention.StdCall ), SuppressUnmanagedCodeSecurity]
- public extern static Int32 joyGetPosEx( Int32 uJoyID, ref JOYINFOEX pji);
- [DllImport("winmm.dll", CallingConvention = CallingConvention.StdCall), SuppressUnmanagedCodeSecurity]
- public extern static Int32 joyGetPos(Int32 uJoyID, ref JOYINFO pji);
- public Form1()
- {
- InitializeComponent();
- mJoystickEx = new JOYINFOEX();
- mJoystickEx.dwSize = System.Runtime.InteropServices.Marshal.SizeOf( mJoystickEx );
- }
- private void onTimer(object sender, EventArgs e)
- {
- int res = joyGetPosEx( 0, ref mJoystickEx );
- this.Invalidate();
- int jkj = 0;
- }
- private void onPaint(object sender, PaintEventArgs e)
- {
- Graphics gr = e.Graphics;
- String str;
- str = String.Format("X = {0}", mJoystickEx.dwXpos);
- gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 10);
- str = String.Format("Y = {0}", mJoystick.wYpos);
- gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 30);
- str = String.Format("Z = {0}", mJoystick.wZpos);
- gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 50);
- str = String.Format("but = {0}", mJoystick.wButtons);
- gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 70);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement