Advertisement
Guest User

Lapis

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. using System.Runtime.InteropServices;
  11.  
  12. namespace joystickCS
  13. {
  14. public partial class Form1 : Form
  15. {
  16.  
  17.  
  18. public struct JOYINFOEX{
  19. public Int32 dwSize; /* size of structure */
  20. public Int32 dwFlags; /* flags to indicate what to return */
  21. public Int32 dwXpos; /* x position */
  22. public Int32 dwYpos; /* y position */
  23. public Int32 dwZpos; /* z position */
  24. public Int32 dwRpos; /* rudder/4th axis position */
  25. public Int32 dwUpos; /* 5th axis position */
  26. public Int32 dwVpos; /* 6th axis position */
  27. public Int32 dwButtons; /* button states */
  28. public Int32 dwButtonNumber; /* current button number pressed */
  29. public Int32 dwPOV; /* point of view state */
  30. public Int32 dwReserved1; /* reserved for communication between winmm & driver */
  31. public Int32 dwReserved2; /* reserved for future expansion */
  32. };
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. [DllImport( "winmm.dll", CallingConvention= CallingConvention.StdCall)]
  40. public extern static Int32 joyGetPosEx( Int32 uJoyID, ref JOYINFOEX pji);
  41.  
  42.  
  43. //Int32 joyGetPosEx( Int32 uJoyID, __out LPJOYINFOEX pji);
  44.  
  45.  
  46. JOYINFOEX mJoyInfo;
  47.  
  48. public Form1()
  49. {
  50. InitializeComponent();
  51.  
  52. mJoyInfo = new JOYINFOEX();
  53. mJoyInfo.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(mJoyInfo);
  54. timer1.Enabled = true;
  55. }
  56.  
  57. private void onTimer(object sender, EventArgs e)
  58. {
  59. int res = joyGetPosEx(0, ref mJoyInfo);
  60. this.Invalidate();
  61. }
  62.  
  63. private void onPaint(object sender, PaintEventArgs e)
  64. {
  65. Graphics gr = e.Graphics;
  66.  
  67. String str;
  68.  
  69. str = String.Format("X: {0}", mJoyInfo.dwXpos);
  70. gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 10);
  71. str = String.Format("Y: {0}", mJoyInfo.dwYpos);
  72. gr.DrawString(str, SystemFonts.DefaultFont, Brushes.Black, 10, 30);
  73.  
  74.  
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement