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