Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
810 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Probleme d'affichage boutons joystick, DirectX

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Probleme d'affichage boutons joystick, DirectX

n°1992258
cutprod
Posté le 11-05-2010 à 18:50:18  profilanswer
 

Bonjour à tous, je reviens vers vous pour avoir un peu d'aide :
J'ai réussi à trouver sur le net une source en visual basic qui me donne les infos de mon joystick. Tous fonctionne très bien sauf les boutons!
Le label bouton devrait m'afficher le numéro du bouton presser mais il n'affiche que zéro (pour chaque boutons il détecte la pression mais affiche zéro) je ne peux donc pas attribuer différentes actions aux boutons.
 
J'ai la même source en c++ et elle m'affiche bien les différents boutons, mais vu que je suis pas trop bon en prog , j'arrive pas à trouver la solution pour faire tournée celle-ci.
 
Voici la source si quelqu'un peut m'aider.
 

Code :
  1. Imports Microsoft.DirectX
  2. Imports Microsoft.DirectX.DirectInput
  3. Public Class Form1
  4. Inherits System.Windows.Forms.Form
  5. ' code added to dispose in windows for designer generated code
  6. #Region " Windows Form Designer generated code "
  7. Public Sub New()
  8. MyBase.New()
  9. 'This call is required by the Windows Form Designer.
  10. InitializeComponent()
  11. 'Add any initialization after the InitializeComponent() call
  12. End Sub
  13. 'Form overrides dispose to clean up the component list.
  14. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  15. timer1.Stop()
  16. ' Unacquire all DirectInput objects.
  17. If Not applicationDevice Is Nothing Then applicationDevice.Unacquire()
  18. If disposing Then
  19. If Not (components Is Nothing) Then
  20. components.Dispose()
  21. End If
  22. End If
  23. MyBase.Dispose(disposing)
  24. End Sub
  25. 'Required by the Windows Form Designer
  26. Private components As System.ComponentModel.IContainer
  27. 'NOTE: The following procedure is required by the Windows Form Designer
  28. 'It can be modified using the Windows Form Designer.
  29. 'Do not modify it using the code editor.
  30. Friend WithEvents label2 As System.Windows.Forms.Label
  31. Friend WithEvents buttonExit As System.Windows.Forms.Button
  32. Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
  33. Friend WithEvents labelButtons As System.Windows.Forms.Label
  34. Friend WithEvents label1 As System.Windows.Forms.Label
  35. Friend WithEvents labelPOV3 As System.Windows.Forms.Label
  36. Friend WithEvents labelSlider1 As System.Windows.Forms.Label
  37. Friend WithEvents labelSlider0 As System.Windows.Forms.Label
  38. Friend WithEvents labelPOV2 As System.Windows.Forms.Label
  39. Friend WithEvents labelPOV1 As System.Windows.Forms.Label
  40. Friend WithEvents labelPOV0 As System.Windows.Forms.Label
  41. Friend WithEvents labelZRotation As System.Windows.Forms.Label
  42. Friend WithEvents labelYRotation As System.Windows.Forms.Label
  43. Friend WithEvents labelXRotation As System.Windows.Forms.Label
  44. Friend WithEvents labelZAxis As System.Windows.Forms.Label
  45. Friend WithEvents labelYAxis As System.Windows.Forms.Label
  46. Friend WithEvents labelXAxis As System.Windows.Forms.Label
  47. Friend WithEvents labelPOV3Text As System.Windows.Forms.Label
  48. Friend WithEvents labelPOV2Text As System.Windows.Forms.Label
  49. Friend WithEvents labelPOV1Text As System.Windows.Forms.Label
  50. Friend WithEvents labelPOV0Text As System.Windows.Forms.Label
  51. Friend WithEvents labelSlider1Text As System.Windows.Forms.Label
  52. Friend WithEvents labelSlider0Text As System.Windows.Forms.Label
  53. Friend WithEvents labelZRotationText As System.Windows.Forms.Label
  54. Friend WithEvents labelYRotationText As System.Windows.Forms.Label
  55. Friend WithEvents labelXRotationText As System.Windows.Forms.Label
  56. Friend WithEvents labelZAxisText As System.Windows.Forms.Label
  57. Friend WithEvents labelYAxisText As System.Windows.Forms.Label
  58. Friend WithEvents labelXAxisText As System.Windows.Forms.Label
  59. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  60. Me.label2 = New System.Windows.Forms.Label
  61. Me.buttonExit = New System.Windows.Forms.Button
  62. Me.groupBox1 = New System.Windows.Forms.GroupBox
  63. Me.labelButtons = New System.Windows.Forms.Label
  64. Me.label1 = New System.Windows.Forms.Label
  65. Me.labelPOV3 = New System.Windows.Forms.Label
  66. Me.labelSlider1 = New System.Windows.Forms.Label
  67. Me.labelSlider0 = New System.Windows.Forms.Label
  68. Me.labelPOV2 = New System.Windows.Forms.Label
  69. Me.labelPOV1 = New System.Windows.Forms.Label
  70. Me.labelPOV0 = New System.Windows.Forms.Label
  71. Me.labelZRotation = New System.Windows.Forms.Label
  72. Me.labelYRotation = New System.Windows.Forms.Label
  73. Me.labelXRotation = New System.Windows.Forms.Label
  74. Me.labelZAxis = New System.Windows.Forms.Label
  75. Me.labelYAxis = New System.Windows.Forms.Label
  76. Me.labelXAxis = New System.Windows.Forms.Label
  77. Me.labelPOV3Text = New System.Windows.Forms.Label
  78. Me.labelPOV2Text = New System.Windows.Forms.Label
  79. Me.labelPOV1Text = New System.Windows.Forms.Label
  80. Me.labelPOV0Text = New System.Windows.Forms.Label
  81. Me.labelSlider1Text = New System.Windows.Forms.Label
  82. Me.labelSlider0Text = New System.Windows.Forms.Label
  83. Me.labelZRotationText = New System.Windows.Forms.Label
  84. Me.labelYRotationText = New System.Windows.Forms.Label
  85. Me.labelXRotationText = New System.Windows.Forms.Label
  86. Me.labelZAxisText = New System.Windows.Forms.Label
  87. Me.labelYAxisText = New System.Windows.Forms.Label
  88. Me.labelXAxisText = New System.Windows.Forms.Label
  89. Me.groupBox1.SuspendLayout()
  90. Me.SuspendLayout()
  91. '
  92. 'label2
  93. '
  94. Me.label2.AutoSize = True
  95. Me.label2.Location = New System.Drawing.Point(24, 8)
  96. Me.label2.Name = "label2"
  97. Me.label2.Size = New System.Drawing.Size(258, 16)
  98. Me.label2.TabIndex = 4
  99. Me.label2.Text = "This sample continously polls the Joystick for data."
  100. '
  101. 'buttonExit
  102. '
  103. Me.buttonExit.Location = New System.Drawing.Point(248, 248)
  104. Me.buttonExit.Name = "buttonExit"
  105. Me.buttonExit.Size = New System.Drawing.Size(40, 24)
  106. Me.buttonExit.TabIndex = 3
  107. Me.buttonExit.Text = "Exit"
  108. '
  109. 'groupBox1
  110. '
  111. Me.groupBox1.Controls.Add(Me.labelButtons)
  112. Me.groupBox1.Controls.Add(Me.label1)
  113. Me.groupBox1.Controls.Add(Me.labelPOV3)
  114. Me.groupBox1.Controls.Add(Me.labelSlider1)
  115. Me.groupBox1.Controls.Add(Me.labelSlider0)
  116. Me.groupBox1.Controls.Add(Me.labelPOV2)
  117. Me.groupBox1.Controls.Add(Me.labelPOV1)
  118. Me.groupBox1.Controls.Add(Me.labelPOV0)
  119. Me.groupBox1.Controls.Add(Me.labelZRotation)
  120. Me.groupBox1.Controls.Add(Me.labelYRotation)
  121. Me.groupBox1.Controls.Add(Me.labelXRotation)
  122. Me.groupBox1.Controls.Add(Me.labelZAxis)
  123. Me.groupBox1.Controls.Add(Me.labelYAxis)
  124. Me.groupBox1.Controls.Add(Me.labelXAxis)
  125. Me.groupBox1.Controls.Add(Me.labelPOV3Text)
  126. Me.groupBox1.Controls.Add(Me.labelPOV2Text)
  127. Me.groupBox1.Controls.Add(Me.labelPOV1Text)
  128. Me.groupBox1.Controls.Add(Me.labelPOV0Text)
  129. Me.groupBox1.Controls.Add(Me.labelSlider1Text)
  130. Me.groupBox1.Controls.Add(Me.labelSlider0Text)
  131. Me.groupBox1.Controls.Add(Me.labelZRotationText)
  132. Me.groupBox1.Controls.Add(Me.labelYRotationText)
  133. Me.groupBox1.Controls.Add(Me.labelXRotationText)
  134. Me.groupBox1.Controls.Add(Me.labelZAxisText)
  135. Me.groupBox1.Controls.Add(Me.labelYAxisText)
  136. Me.groupBox1.Controls.Add(Me.labelXAxisText)
  137. Me.groupBox1.Location = New System.Drawing.Point(24, 48)
  138. Me.groupBox1.Name = "groupBox1"
  139. Me.groupBox1.Size = New System.Drawing.Size(264, 184)
  140. Me.groupBox1.TabIndex = 2
  141. Me.groupBox1.TabStop = False
  142. Me.groupBox1.Text = "Joystick State"
  143. '
  144. 'labelButtons
  145. '
  146. Me.labelButtons.Location = New System.Drawing.Point(72, 157)
  147. Me.labelButtons.Name = "labelButtons"
  148. Me.labelButtons.Size = New System.Drawing.Size(184, 13)
  149. Me.labelButtons.TabIndex = 25
  150. '
  151. 'label1
  152. '
  153. Me.label1.AutoSize = True
  154. Me.label1.Location = New System.Drawing.Point(16, 157)
  155. Me.label1.Name = "label1"
  156. Me.label1.Size = New System.Drawing.Size(46, 16)
  157. Me.label1.TabIndex = 24
  158. Me.label1.Text = "Buttons:"
  159. '
  160. 'labelPOV3
  161. '
  162. Me.labelPOV3.AutoSize = True
  163. Me.labelPOV3.Enabled = False
  164. Me.labelPOV3.Location = New System.Drawing.Point(192, 128)
  165. Me.labelPOV3.Name = "labelPOV3"
  166. Me.labelPOV3.Size = New System.Drawing.Size(10, 16)
  167. Me.labelPOV3.TabIndex = 23
  168. Me.labelPOV3.Text = "0"
  169. '
  170. 'labelSlider1
  171. '
  172. Me.labelSlider1.AutoSize = True
  173. Me.labelSlider1.Enabled = False
  174. Me.labelSlider1.Location = New System.Drawing.Point(192, 40)
  175. Me.labelSlider1.Name = "labelSlider1"
  176. Me.labelSlider1.Size = New System.Drawing.Size(10, 16)
  177. Me.labelSlider1.TabIndex = 22
  178. Me.labelSlider1.Text = "0"
  179. '
  180. 'labelSlider0
  181. '
  182. Me.labelSlider0.AutoSize = True
  183. Me.labelSlider0.Enabled = False
  184. Me.labelSlider0.Location = New System.Drawing.Point(192, 24)
  185. Me.labelSlider0.Name = "labelSlider0"
  186. Me.labelSlider0.Size = New System.Drawing.Size(10, 16)
  187. Me.labelSlider0.TabIndex = 21
  188. Me.labelSlider0.Text = "0"
  189. '
  190. 'labelPOV2
  191. '
  192. Me.labelPOV2.AutoSize = True
  193. Me.labelPOV2.Enabled = False
  194. Me.labelPOV2.Location = New System.Drawing.Point(192, 112)
  195. Me.labelPOV2.Name = "labelPOV2"
  196. Me.labelPOV2.Size = New System.Drawing.Size(10, 16)
  197. Me.labelPOV2.TabIndex = 20
  198. Me.labelPOV2.Text = "0"
  199. '
  200. 'labelPOV1
  201. '
  202. Me.labelPOV1.AutoSize = True
  203. Me.labelPOV1.Enabled = False
  204. Me.labelPOV1.Location = New System.Drawing.Point(192, 96)
  205. Me.labelPOV1.Name = "labelPOV1"
  206. Me.labelPOV1.Size = New System.Drawing.Size(10, 16)
  207. Me.labelPOV1.TabIndex = 19
  208. Me.labelPOV1.Text = "0"
  209. '
  210. 'labelPOV0
  211. '
  212. Me.labelPOV0.AutoSize = True
  213. Me.labelPOV0.Enabled = False
  214. Me.labelPOV0.Location = New System.Drawing.Point(192, 80)
  215. Me.labelPOV0.Name = "labelPOV0"
  216. Me.labelPOV0.Size = New System.Drawing.Size(10, 16)
  217. Me.labelPOV0.TabIndex = 18
  218. Me.labelPOV0.Text = "0"
  219. '
  220. 'labelZRotation
  221. '
  222. Me.labelZRotation.AutoSize = True
  223. Me.labelZRotation.Enabled = False
  224. Me.labelZRotation.Location = New System.Drawing.Point(88, 128)
  225. Me.labelZRotation.Name = "labelZRotation"
  226. Me.labelZRotation.Size = New System.Drawing.Size(10, 16)
  227. Me.labelZRotation.TabIndex = 17
  228. Me.labelZRotation.Text = "0"
  229. '
  230. 'labelYRotation
  231. '
  232. Me.labelYRotation.AutoSize = True
  233. Me.labelYRotation.Enabled = False
  234. Me.labelYRotation.Location = New System.Drawing.Point(88, 112)
  235. Me.labelYRotation.Name = "labelYRotation"
  236. Me.labelYRotation.Size = New System.Drawing.Size(10, 16)
  237. Me.labelYRotation.TabIndex = 16
  238. Me.labelYRotation.Text = "0"
  239. '
  240. 'labelXRotation
  241. '
  242. Me.labelXRotation.AutoSize = True
  243. Me.labelXRotation.Enabled = False
  244. Me.labelXRotation.Location = New System.Drawing.Point(88, 96)
  245. Me.labelXRotation.Name = "labelXRotation"
  246. Me.labelXRotation.Size = New System.Drawing.Size(10, 16)
  247. Me.labelXRotation.TabIndex = 15
  248. Me.labelXRotation.Text = "0"
  249. '
  250. 'labelZAxis
  251. '
  252. Me.labelZAxis.AutoSize = True
  253. Me.labelZAxis.Enabled = False
  254. Me.labelZAxis.Location = New System.Drawing.Point(88, 56)
  255. Me.labelZAxis.Name = "labelZAxis"
  256. Me.labelZAxis.Size = New System.Drawing.Size(10, 16)
  257. Me.labelZAxis.TabIndex = 14
  258. Me.labelZAxis.Text = "0"
  259. '
  260. 'labelYAxis
  261. '
  262. Me.labelYAxis.AutoSize = True
  263. Me.labelYAxis.Enabled = False
  264. Me.labelYAxis.Location = New System.Drawing.Point(88, 40)
  265. Me.labelYAxis.Name = "labelYAxis"
  266. Me.labelYAxis.Size = New System.Drawing.Size(10, 16)
  267. Me.labelYAxis.TabIndex = 13
  268. Me.labelYAxis.Text = "0"
  269. '
  270. 'labelXAxis
  271. '
  272. Me.labelXAxis.AutoSize = True
  273. Me.labelXAxis.Enabled = False
  274. Me.labelXAxis.Location = New System.Drawing.Point(88, 24)
  275. Me.labelXAxis.Name = "labelXAxis"
  276. Me.labelXAxis.Size = New System.Drawing.Size(10, 16)
  277. Me.labelXAxis.TabIndex = 12
  278. Me.labelXAxis.Text = "0"
  279. '
  280. 'labelPOV3Text
  281. '
  282. Me.labelPOV3Text.AutoSize = True
  283. Me.labelPOV3Text.Enabled = False
  284. Me.labelPOV3Text.Location = New System.Drawing.Point(136, 128)
  285. Me.labelPOV3Text.Name = "labelPOV3Text"
  286. Me.labelPOV3Text.Size = New System.Drawing.Size(41, 16)
  287. Me.labelPOV3Text.TabIndex = 11
  288. Me.labelPOV3Text.Text = "POV 3:"
  289. '
  290. 'labelPOV2Text
  291. '
  292. Me.labelPOV2Text.AutoSize = True
  293. Me.labelPOV2Text.Enabled = False
  294. Me.labelPOV2Text.Location = New System.Drawing.Point(136, 112)
  295. Me.labelPOV2Text.Name = "labelPOV2Text"
  296. Me.labelPOV2Text.Size = New System.Drawing.Size(41, 16)
  297. Me.labelPOV2Text.TabIndex = 10
  298. Me.labelPOV2Text.Text = "POV 2:"
  299. '
  300. 'labelPOV1Text
  301. '
  302. Me.labelPOV1Text.AutoSize = True
  303. Me.labelPOV1Text.Enabled = False
  304. Me.labelPOV1Text.Location = New System.Drawing.Point(136, 96)
  305. Me.labelPOV1Text.Name = "labelPOV1Text"
  306. Me.labelPOV1Text.Size = New System.Drawing.Size(41, 16)
  307. Me.labelPOV1Text.TabIndex = 9
  308. Me.labelPOV1Text.Text = "POV 1:"
  309. '
  310. 'labelPOV0Text
  311. '
  312. Me.labelPOV0Text.AutoSize = True
  313. Me.labelPOV0Text.Enabled = False
  314. Me.labelPOV0Text.Location = New System.Drawing.Point(136, 80)
  315. Me.labelPOV0Text.Name = "labelPOV0Text"
  316. Me.labelPOV0Text.Size = New System.Drawing.Size(41, 16)
  317. Me.labelPOV0Text.TabIndex = 8
  318. Me.labelPOV0Text.Text = "POV 0:"
  319. '
  320. 'labelSlider1Text
  321. '
  322. Me.labelSlider1Text.AutoSize = True
  323. Me.labelSlider1Text.Enabled = False
  324. Me.labelSlider1Text.Location = New System.Drawing.Point(136, 40)
  325. Me.labelSlider1Text.Name = "labelSlider1Text"
  326. Me.labelSlider1Text.Size = New System.Drawing.Size(46, 16)
  327. Me.labelSlider1Text.TabIndex = 7
  328. Me.labelSlider1Text.Text = "Slider 1:"
  329. '
  330. 'labelSlider0Text
  331. '
  332. Me.labelSlider0Text.AutoSize = True
  333. Me.labelSlider0Text.Enabled = False
  334. Me.labelSlider0Text.Location = New System.Drawing.Point(136, 24)
  335. Me.labelSlider0Text.Name = "labelSlider0Text"
  336. Me.labelSlider0Text.Size = New System.Drawing.Size(46, 16)
  337. Me.labelSlider0Text.TabIndex = 6
  338. Me.labelSlider0Text.Text = "Slider 0:"
  339. '
  340. 'labelZRotationText
  341. '
  342. Me.labelZRotationText.AutoSize = True
  343. Me.labelZRotationText.Enabled = False
  344. Me.labelZRotationText.Location = New System.Drawing.Point(16, 128)
  345. Me.labelZRotationText.Name = "labelZRotationText"
  346. Me.labelZRotationText.Size = New System.Drawing.Size(60, 16)
  347. Me.labelZRotationText.TabIndex = 5
  348. Me.labelZRotationText.Text = "Z Rotation:"
  349. '
  350. 'labelYRotationText
  351. '
  352. Me.labelYRotationText.AutoSize = True
  353. Me.labelYRotationText.Enabled = False
  354. Me.labelYRotationText.Location = New System.Drawing.Point(16, 112)
  355. Me.labelYRotationText.Name = "labelYRotationText"
  356. Me.labelYRotationText.Size = New System.Drawing.Size(60, 16)
  357. Me.labelYRotationText.TabIndex = 4
  358. Me.labelYRotationText.Text = "Y Rotation:"
  359. '
  360. 'labelXRotationText
  361. '
  362. Me.labelXRotationText.AutoSize = True
  363. Me.labelXRotationText.Enabled = False
  364. Me.labelXRotationText.Location = New System.Drawing.Point(16, 96)
  365. Me.labelXRotationText.Name = "labelXRotationText"
  366. Me.labelXRotationText.Size = New System.Drawing.Size(60, 16)
  367. Me.labelXRotationText.TabIndex = 3
  368. Me.labelXRotationText.Text = "X Rotation:"
  369. '
  370. 'labelZAxisText
  371. '
  372. Me.labelZAxisText.AutoSize = True
  373. Me.labelZAxisText.Enabled = False
  374. Me.labelZAxisText.Location = New System.Drawing.Point(16, 56)
  375. Me.labelZAxisText.Name = "labelZAxisText"
  376. Me.labelZAxisText.Size = New System.Drawing.Size(39, 16)
  377. Me.labelZAxisText.TabIndex = 2
  378. Me.labelZAxisText.Text = "Z Axis:"
  379. '
  380. 'labelYAxisText
  381. '
  382. Me.labelYAxisText.AutoSize = True
  383. Me.labelYAxisText.Enabled = False
  384. Me.labelYAxisText.Location = New System.Drawing.Point(16, 40)
  385. Me.labelYAxisText.Name = "labelYAxisText"
  386. Me.labelYAxisText.Size = New System.Drawing.Size(39, 16)
  387. Me.labelYAxisText.TabIndex = 1
  388. Me.labelYAxisText.Text = "Y Axis:"
  389. '
  390. 'labelXAxisText
  391. '
  392. Me.labelXAxisText.AutoSize = True
  393. Me.labelXAxisText.Enabled = False
  394. Me.labelXAxisText.Location = New System.Drawing.Point(16, 24)
  395. Me.labelXAxisText.Name = "labelXAxisText"
  396. Me.labelXAxisText.Size = New System.Drawing.Size(39, 16)
  397. Me.labelXAxisText.TabIndex = 0
  398. Me.labelXAxisText.Text = "X Axis:"
  399. '
  400. 'Form1
  401. '
  402. Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  403. Me.ClientSize = New System.Drawing.Size(320, 301)
  404. Me.Controls.Add(Me.label2)
  405. Me.Controls.Add(Me.buttonExit)
  406. Me.Controls.Add(Me.groupBox1)
  407. Me.Name = "Form1"
  408. Me.Text = "Form1"
  409. Me.groupBox1.ResumeLayout(False)
  410. Me.ResumeLayout(False)
  411. End Sub
  412. #End Region
  413. ' Translation of the MS DirectX SDK Joystick example to vb
  414. ' These three fields hold common data that
  415. ' different threads will have to access
  416. Public Shared state As New JoystickState
  417. Private applicationDevice As Device = Nothing
  418. Public Shared numPOVs As Integer = 0
  419. Private SliderCount As Integer = 0 ' number of returned slider controls
  420. Private WithEvents timer1 As New Timer
  421. Private Function InitDirectInput() As Boolean
  422. ' loop through attached game controller devices
  423. For Each instance As DeviceInstance In Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)
  424. ' example just picks the first available
  425. applicationDevice = New Device(instance.InstanceGuid)
  426. Exit For
  427. Next
  428. ' If we didn't find one then let user know and quit
  429. If applicationDevice Is Nothing Then
  430. MessageBox.Show("Unable to create a Joystick device. Sample will exit.", "No joystick found" )
  431. Return False
  432. End If
  433. ' Set the data format to the c_dfDIJoystick pre-defined format.
  434. applicationDevice.SetDataFormat(DeviceDataFormat.Joystick)
  435. ' Set the cooperative level for the device.
  436. ' (The logical OR here has the effect of making it Exclusive and foreground)
  437. applicationDevice.SetCooperativeLevel(Me, CooperativeLevelFlags.Exclusive Or CooperativeLevelFlags.Foreground)
  438. ' Enumerate all the objects on the device.
  439. For Each d As DeviceObjectInstance In applicationDevice.Objects
  440. ' For axes that are returned, set the DIPROP_RANGE property for the
  441. ' enumerated axis in order to scale min/max values.
  442. If Not (d.ObjectId And Convert.ToInt32(DeviceObjectTypeFlags.Axis)) = 0 Then
  443. ' Set the range for the axis.
  444. applicationDevice.Properties.SetRange(ParameterHow.ById, d.ObjectId, New InputRange(-1000, +1000))
  445. ' Update the controls to reflect what
  446. ' objects the device supports.
  447. UpdateControls(d)
  448. End If
  449. Next
  450. Return True
  451. End Function
  452. Private Sub buttonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonExit.Click
  453. Close()
  454. End Sub
  455. Public Sub GetData()
  456. ' Make sure there is a valid device.
  457. If applicationDevice Is Nothing Then Return
  458. Try
  459. ' Poll the device for info.
  460. applicationDevice.Poll()
  461. Catch notAcqEx As NotAcquiredException
  462. ' Check to see if either the app
  463. ' needs to acquire the device, or
  464. ' if the app lost the device to another
  465. ' process.
  466. Try
  467. ' Acquire the device.
  468. applicationDevice.Acquire()
  469. Catch iex As InputException
  470. ' Failed to acquire the device.
  471. ' This could be because the app
  472. ' doesn't have focus.
  473. Return
  474. End Try
  475. Catch inpLostEx As InputLostException
  476. ' Check to see if either the app
  477. ' needs to acquire the device, or
  478. ' if the app lost the device to another
  479. ' process.
  480. Try
  481. ' Acquire the device.
  482. applicationDevice.Acquire()
  483. Catch iex As InputException
  484. ' Failed to acquire the device.
  485. ' This could be because the app
  486. ' doesn't have focus.
  487. Return
  488. End Try
  489. End Try
  490. ' Get the state of the device.
  491. Try
  492. state = applicationDevice.CurrentJoystickState
  493. ' Catch any exceptions. None will be handled here,
  494. ' any device re-aquisition will be handled above.
  495. Catch iex As InputException
  496. Return
  497. End Try
  498. UpdateUI()
  499. End Sub
  500. Private Sub UpdateUI()
  501. ' This function updated the UI with
  502. ' Joystick state information.
  503. Dim strText As String = ""
  504. labelXAxis.Text = state.X.ToString()
  505. labelYAxis.Text = state.Y.ToString()
  506. labelZAxis.Text = state.Z.ToString()
  507. labelXRotation.Text = state.Rx.ToString()
  508. labelYRotation.Text = state.Ry.ToString()
  509. labelZRotation.Text = state.Rz.ToString()
  510. Dim slider As Integer() = state.GetSlider()
  511. labelSlider0.Text = slider(0).ToString()
  512. labelSlider1.Text = slider(1).ToString()
  513. Dim pov As Integer() = state.GetPointOfView()
  514. labelPOV0.Text = pov(0).ToString()
  515. labelPOV1.Text = pov(1).ToString()
  516. labelPOV2.Text = pov(2).ToString()
  517. labelPOV3.Text = pov(3).ToString()
  518. ' Fill up text with which buttons are pressed
  519. Dim buttons As Byte() = state.GetButtons()
  520. Dim _button As Integer = 0
  521. For Each b As Byte In buttons
  522. If Not ((b And &H80) = 0) Then
  523. strText += _button.ToString(" 00" )
  524. _button += 1
  525. End If
  526. Next
  527. labelButtons.Text = strText
  528. End Sub
  529. Public Sub UpdateControls(ByVal d As DeviceObjectInstance)
  530. ' Set the UI to reflect what objects the Joystick supports.
  531. If (ObjectTypeGuid.XAxis.Equals(d.ObjectType)) Then
  532. labelXAxis.Enabled = True
  533. labelXAxisText.Enabled = True
  534. End If
  535. If (ObjectTypeGuid.YAxis.Equals(d.ObjectType)) Then
  536. labelYAxis.Enabled = True
  537. labelYAxisText.Enabled = True
  538. End If
  539. If (ObjectTypeGuid.ZAxis.Equals(d.ObjectType)) Then
  540. labelZAxis.Enabled = True
  541. labelZAxisText.Enabled = True
  542. End If
  543. If (ObjectTypeGuid.RxAxis.Equals(d.ObjectType)) Then
  544. labelXRotation.Enabled = True
  545. labelXRotationText.Enabled = True
  546. End If
  547. If (ObjectTypeGuid.RyAxis.Equals(d.ObjectType)) Then
  548. labelYRotation.Enabled = True
  549. labelYRotationText.Enabled = True
  550. End If
  551. If (ObjectTypeGuid.RzAxis.Equals(d.ObjectType)) Then
  552. labelZRotation.Enabled = True
  553. labelZRotationText.Enabled = True
  554. End If
  555. If (ObjectTypeGuid.Slider.Equals(d.ObjectType)) Then
  556. SliderCount += 1
  557. Select Case SliderCount
  558. Case 0
  559. labelSlider0.Enabled = True
  560. labelSlider0Text.Enabled = True
  561. Case 1
  562. labelSlider1.Enabled = True
  563. labelSlider1Text.Enabled = True
  564. End Select
  565. End If
  566. If (ObjectTypeGuid.PointOfView.Equals(d.ObjectType)) Then
  567. numPOVs += 1
  568. Select Case numPOVs
  569. Case 0
  570. labelPOV0.Enabled = True
  571. labelPOV0Text.Enabled = True
  572. Case 1
  573. labelPOV1.Enabled = True
  574. labelPOV1Text.Enabled = True
  575. Case 2
  576. labelPOV2.Enabled = True
  577. labelPOV2Text.Enabled = True
  578. Case 3
  579. labelPOV3.Enabled = True
  580. labelPOV3Text.Enabled = True
  581. End Select
  582. End If
  583. End Sub
  584. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  585. If InitDirectInput() = False Then Close()
  586. timer1.Start()
  587. End Sub
  588. Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick
  589. GetData()
  590. End Sub
  591. End Class


 
Je pense que l'erreur se situe en bas dans la sub : Private Sub UpdateUI()
Je peux vous coller le code en c++ qui fonctionne si ca peut vous aider!

mood
Publicité
Posté le 11-05-2010 à 18:50:18  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Probleme d'affichage boutons joystick, DirectX

 

Sujets relatifs
Probleme de chargement du ViewState avec Update Panel Ajax.Pb d'affichage conditionnel d'objet dans un état
[Résolu] Problème getElementById IE8 et safariProblème sur une macro Excel
affichageProblème à inséré du JQUERY
Problème retour arrière avec STDIN[js] problème avec jquery
problème de grep avec la commande systemprobleme avec la fonction mail
Plus de sujets relatifs à : Probleme d'affichage boutons joystick, DirectX


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR