Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.Runtime.InteropServices;
  12.  
  13. namespace csJoy
  14. {
  15. public partial class Form1 : Form
  16. {
  17.  
  18.  
  19. public struct JOYINFOEX
  20. {
  21. public Int32 dwSize; /* size of structure */
  22. public Int32 dwFlags; /* flags to indicate what to return */
  23. public Int32 dwXpos; /* x position */
  24. public Int32 dwYpos; /* y position */
  25. public Int32 dwZpos; /* z position */
  26. public Int32 dwRpos; /* rudder/4th axis position */
  27. public Int32 dwUpos; /* 5th axis position */
  28. public Int32 dwVpos; /* 6th axis position */
  29. public Int32 dwButtons; /* button states */
  30. public Int32 dwButtonNumber; /* current button number pressed */
  31. public Int32 dwPOV; /* point of view state */
  32. public Int32 dwReserved1; /* reserved for communication between winmm & driver */
  33. public Int32 dwReserved2; /* reserved for future expansion */
  34. }
  35.  
  36.  
  37. JOYINFOEX joystickInfo;
  38.  
  39. [System.Runtime.InteropServices.DllImport("winmm.dll", CallingConvention = CallingConvention.StdCall)]
  40. public static extern UInt32 joyGetPosEx( UInt32 uJoyID, ref JOYINFOEX pji );
  41.  
  42. public Form1()
  43. {
  44. InitializeComponent();
  45.  
  46.  
  47. joystickInfo.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(joystickInfo);
  48. joystickInfo.dwFlags = 0xFFFF;
  49.  
  50.  
  51. UInt32 joyRes = joyGetPosEx( 0, ref joystickInfo);
  52.  
  53. int jjj = 0;
  54.  
  55. }
  56.  
  57. private void onTimer(object sender, EventArgs e)
  58. {
  59. joystickInfo.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(joystickInfo);
  60. joystickInfo.dwFlags = 0xFFFF;
  61.  
  62.  
  63. UInt32 joyRes = joyGetPosEx(0, ref joystickInfo);
  64.  
  65. this.Invalidate();
  66. }
  67.  
  68. private void onPaint(object sender, PaintEventArgs e)
  69. {
  70. Graphics gr = e.Graphics;
  71.  
  72. string str = String.Format( "X Y Z: {0} {1} {2} ",
  73. joystickInfo.dwXpos,
  74. joystickInfo.dwYpos,
  75. joystickInfo.dwZpos);
  76.  
  77. gr.DrawString(str, SystemFonts.CaptionFont, Brushes.Black, 10, 10);
  78.  
  79. //dc.TextOut(10, 10, str);
  80.  
  81.  
  82. /*str.Format(L"R U V: %04X %04X %04X ",
  83. joystickInfo.dwRpos,
  84. joystickInfo.dwUpos,
  85. joystickInfo.dwVpos);
  86. dc.TextOut(10, 30, str);
  87. str.Format(L"P B N: %04X %04X %04X ",
  88. joystickInfo.dwPOV,
  89. joystickInfo.dwButtons,
  90. joystickInfo.dwButtonNumber);
  91. dc.TextOut(10, 50, str);*/
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement