source: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/MM/Joystick.ab@ 594

Last change on this file since 594 was 594, checked in by NoWest, 16 years ago

MIDI出力関連のMidiOutクラスを追加。
Joystick.abを改良。ListをIlistに変更。

File size: 13.9 KB
Line 
1
2'#require <api_mmsys.sbp>
3
4Namespace ActiveBasic
5Namespace Windows
6Namespace MM
7
8'ジョイスティックの構成を表す列挙体
9Enum JoyCapability
10 'ジョイスティックはZ軸情報を所有
11 HasZ = &H0001
12 'ジョイスティックはR軸情報を所有
13 HasR = &H0002
14 'ジョイスティックはU軸情報を所有
15 HasU = &H0004
16 'ジョイスティックはV軸情報を所有
17 HasV = &H0008
18 'ジョイスティックはPoint of View情報を所有
19 HasPointOfView = &H0010
20 'ジョイスティックは4方向Point of Viewサポート
21 PointOfView4Direction = &H0020
22 'ジョイスティックは連続した角度のPoint of Viewをサポート
23 PointOfViewContinuous = &H0040
24End Enum
25
26
27'ジョイスティックの性能を取得するためのJOYCAPS構造体のラップクラス
28Class JoyCaps
29 caps As JOYCAPS
30
31Protected
32 Sub _Initialize ( id As DWord )
33 joyGetDevCaps(id,caps,SizeOf(JOYCAPS))
34 End Sub
35
36Public 'Property
37 '製造業者IDの取得
38 Function ManufacturerID () As Word
39 Return This.caps.wMid
40 End Function
41
42 '製品IDの取得
43 Function ProductID () As Word
44 Return This.caps.wPid
45 End Function
46
47 '製品名の取得
48 Function ProductName () As String
49 Return New System.String(This.caps.szPname As LPTSTR)
50 End Function
51
52 'X軸の最小値の取得
53 Function MinimumX () As DWord
54 Return This.caps.wXmin
55 End Function
56
57 'X軸の最大値の取得
58 Function MaximumX () As DWord
59 Return This.caps.wXmax
60 End Function
61
62 'Y軸の最小値の取得
63 Function MinimumY () As DWord
64 Return This.caps.wYmin
65 End Function
66
67 'Y軸の最大値の取得
68 Function MaximumY () As DWord
69 Return This.caps.wYmax
70 End Function
71
72 'Z軸の最小値の取得
73 Function MinimumZ () As DWord
74 Return This.caps.wZmin
75 End Function
76
77 'Z軸の最大値の取得
78 Function MaximumZ () As DWord
79 Return This.caps.wZmax
80 End Function
81
82 '
83 Function NumberOfButtons () As DWord
84 Return This.caps.wNumButtons
85 End Function
86
87 'キャプチャ時のメッセージ送信間隔の最小値の取得
88 Function MinimumPeriod () As DWord
89 Return This.caps.wPeriodMin
90 End Function
91
92 'キャプチャ時のメッセージ送信間隔の最大値の取得
93 Function MaximumPeriod () As DWord
94 Return This.caps.wPeriodMax
95 End Function
96
97 '4軸目であるラダー(R軸)の最小値の取得
98 Function MinimumR () As DWord
99 Return This.caps.wRmin
100 End Function
101
102 '4軸目であるラダー(R軸)の最大値の取得
103 Function MaximumR () As DWord
104 Return This.caps.wRmax
105 End Function
106
107 '5軸目であるU軸の最小値の取得
108 Function MinimumU () As DWord
109 Return This.caps.wUmin
110 End Function
111
112 '5軸目であるU軸の最大値の取得
113 Function MaximumU () As DWord
114 Return This.caps.wUmax
115 End Function
116
117 '6軸目であるV軸の最小値の取得
118 Function MinimumV () As DWord
119 Return This.caps.wVmin
120 End Function
121
122 '6軸目であるV軸の最大値の取得
123 Function MaximumV () As DWord
124 Return This.caps.wVmax
125 End Function
126
127 'ジョイスティックの構成を取得
128 Function Capabilities () As JoyCapability
129 Return This.caps.wCaps As JoyCapability
130 End Function
131
132 'サポートしている動きの軸の数を取得
133 Function NumberOfSupportedAxes () As DWord
134 Return This.caps.wMaxAxes
135 End Function
136
137 '実際に使用している動きの軸の数を取得
138 Function NumberOfUsedAxes () As DWord
139 Return This.caps.wNumAxes
140 End Function
141
142 'サポートしているボタン数を取得
143 Function NumberOfSupportedButtons () As DWord
144 Return This.caps.wMaxButtons
145 End Function
146
147 '登録キーを文字列の取得
148 Function RegistryKey () As String
149 Return New System.String(This.caps.szRegKey As LPTSTR)
150 End Function
151
152 'OEMジョイスティックドライバを特定する文字列の取得
153 Function OEM_VxD () As String
154 Return New System.String(This.caps.szOEMVxD As LPTSTR)
155 End Function
156End Class
157
158
159'ジョイスティックのボタンの状態を取得するためのクラス
160Class JoyButtons
161 dwButtons As DWord
162
163Protected
164 Sub _Initialize ( dw As DWord )
165 This.dwButtons = dw
166 End Sub
167
168Public 'Property
169 '各ボタンの状態を取得する
170 Function Button1 () As Boolean
171 Return This.Button( 1 )
172 End Function
173 Function Button2 () As Boolean
174 Return This.Button( 2 )
175 End Function
176 Function Button3 () As Boolean
177 Return This.Button( 3 )
178 End Function
179 Function Button4 () As Boolean
180 Return This.Button( 4 )
181 End Function
182 Function Button5 () As Boolean
183 Return This.Button( 5 )
184 End Function
185 Function Button6 () As Boolean
186 Return This.Button( 6 )
187 End Function
188 Function Button7 () As Boolean
189 Return This.Button( 7 )
190 End Function
191 Function Button8 () As Boolean
192 Return This.Button( 8 )
193 End Function
194 Function Button9 () As Boolean
195 Return This.Button( 9 )
196 End Function
197 Function Button10 () As Boolean
198 Return This.Button( 10 )
199 End Function
200 Function Button11 () As Boolean
201 Return This.Button( 11 )
202 End Function
203 Function Button12 () As Boolean
204 Return This.Button( 12 )
205 End Function
206 Function Button13 () As Boolean
207 Return This.Button( 13 )
208 End Function
209 Function Button14 () As Boolean
210 Return This.Button( 14 )
211 End Function
212 Function Button15 () As Boolean
213 Return This.Button( 15 )
214 End Function
215 Function Button16 () As Boolean
216 Return This.Button( 16 )
217 End Function
218 Function Button17 () As Boolean
219 Return This.Button( 17 )
220 End Function
221 Function Button18 () As Boolean
222 Return This.Button( 18 )
223 End Function
224 Function Button19 () As Boolean
225 Return This.Button( 19 )
226 End Function
227 Function Button20 () As Boolean
228 Return This.Button( 20 )
229 End Function
230 Function Button21 () As Boolean
231 Return This.Button( 21 )
232 End Function
233 Function Button22 () As Boolean
234 Return This.Button( 22 )
235 End Function
236 Function Button23 () As Boolean
237 Return This.Button( 23 )
238 End Function
239 Function Button24 () As Boolean
240 Return This.Button( 24 )
241 End Function
242 Function Button25 () As Boolean
243 Return This.Button( 25 )
244 End Function
245 Function Button26 () As Boolean
246 Return This.Button( 26 )
247 End Function
248 Function Button27 () As Boolean
249 Return This.Button( 27 )
250 End Function
251 Function Button28 () As Boolean
252 Return This.Button( 28 )
253 End Function
254 Function Button29 () As Boolean
255 Return This.Button( 29 )
256 End Function
257 Function Button30 () As Boolean
258 Return This.Button( 30 )
259 End Function
260 Function Button31 () As Boolean
261 Return This.Button( 31 )
262 End Function
263 Function Button32 () As Boolean
264 Return This.Button( 32 )
265 End Function
266
267Public 'Method
268 '指定した番号のボタンの状態を取得
269 Function Button ( n As DWord ) As Boolean
270 Return (1<<(n-1) And This.dwButtons) <> 0
271 End Function
272
273Public 'Operator
274 'DWord値へ変換
275 Function Operator () As DWord
276 Return This.dwButtons
277 End Function
278
279 'DWord値と比較
280 Function Operator== (dw As DWord) As Boolean
281 Return This.dwButtons = dw
282 End Function
283 Function Operator<> (dw As DWord) As Boolean
284 Return This.dwButtons <> dw
285 End Function
286
287 'DWord値とAnd演算
288 Function Operator And (dw As DWord) As Boolean
289 Return (This.dwButtons And dw) <> 0
290 End Function
291
292End Class
293
294
295'PointOfView値を格納するクラス
296Class JoyPointOfView
297 pov As DWord
298
299Protected
300 Sub _Initialize ( dw As DWord )
301 If LOWORD(dw) = &HFFFF Then dw = (-1) As DWord
302 This.pov = dw
303 End Sub
304
305Public 'Static Constant
306 '中心
307 Static Const Centered = (-1) As DWord
308 '前方
309 Static Const Forward = 0 As DWord
310 '右前方
311 Static Const ForwardAndRight = 4500 As DWord
312 '右
313 Static Const Right = 9000 As DWord
314 '右後方
315 Static Const BackwardAndRight = 13500 As DWord
316 '後方
317 Static Const Backward = 18000 As DWord
318 '左後方
319 Static Const BackwardAndLeft = 22500 As DWord
320 '左
321 Static Const Left = 27000 As DWord
322 '左前方
323 Static Const ForwardAndLeft = 31500 As DWord
324
325Public 'Proparty
326 Function IsCentered() As Boolean
327 Return This.pov <> Centered
328 End Function
329 Function IsForward() As Boolean
330 Return This.pov <> Forward
331 End Function
332 Function IsRight() As Boolean
333 Return This.pov <> Right
334 End Function
335 Function IsBackward() As Boolean
336 Return This.pov <> Backward
337 End Function
338 Function IsLeft() As Boolean
339 Return This.pov <> Left
340 End Function
341
342Public 'Method
343 '角度に変換
344 Function ToDegrees() As Double
345 Return (This.pov / 100)
346 End Function
347
348
349Public 'Operator
350 'DWord値へ変換
351 Function Operator () As DWord
352 Return This.pov
353 End Function
354
355 'DWord値と比較
356 Function Operator== (value As DWord ) As Boolean
357 Return This.pov = value
358 End Function
359 Function Operator<> ( value As DWord ) As Boolean
360 Return This.pov <> value
361 End Function
362 Function Operator<= ( value As DWord ) As Boolean
363 Return This.pov <= value
364 End Function
365 Function Operator>= ( value As DWord ) As Boolean
366 Return This.pov >= value
367 End Function
368 Function Operator< ( value As DWord ) As Boolean
369 Return This.pov < value
370 End Function
371 Function Operator> ( value As DWord ) As Boolean
372 Return This.pov > value
373 End Function
374
375 'DWord値と演算
376 Function Operator+ ( value As DWord ) As DWord
377 Return This.pov + value
378 End Function
379 Function Operator- ( value As DWord ) As DWord
380 Return This.pov - value
381 End Function
382 Function Operator* ( value As DWord ) As DWord
383 Return This.pov * value
384 End Function
385 Function Operator Mod ( value As DWord ) As DWord
386 Return This.pov Mod value
387 End Function
388 Function Operator / ( value As DWord ) As Double
389 Return This.pov / value
390 End Function
391End Class
392
393
394'ジョイスティックの情報を格納するJOYINFOEX構造体のラップクラス
395Class JoyInfo
396 info As JOYINFOEX
397
398Protected
399 Sub _Initialize ( id As DWord )
400 This.info.dwSize = SizeOf(JOYINFOEX)
401 This.info.dwFlags = JOY_RETURNALL
402 joyGetPosEx(id,info)
403 End Sub
404
405Public 'Property
406 'X軸の値を取得
407 Function X () As DWord
408 Return This.info.dwXpos
409 End Function
410
411 'Y軸の値を取得
412 Function Y () As DWord
413 Return This.info.dwYpos
414 End Function
415
416 'Z軸の値を取得
417 Function Z () As DWord
418 Return This.info.dwZpos
419 End Function
420
421 'ラダー(R軸)の値を取得
422 Function R () As DWord
423 Return This.info.dwRpos
424 End Function
425
426 'U軸の値を取得
427 Function U () As DWord
428 Return This.info.dwUpos
429 End Function
430
431 'V軸の値を取得
432 Function V () As DWord
433 Return This.info.dwVpos
434 End Function
435
436 'ボタンの状態を取得
437 Function Buttons () As JoyButtons
438 Return New Detail._System_JoyButtons(This.info.dwButtons)
439 End Function
440
441 'ボタンの状態を取得
442 Function ButtonNumber () As DWord
443 Return This.info.dwButtonNumber
444 End Function
445 Function PointOfView () As JoyPointOfView
446 Return New Detail._System_JoyPointOfView(This.info.dwPOV)
447 End Function
448End Class
449
450
451'ジョイスティックを扱うためのクラス
452Class JoystickDevice
453 id As DWord
454
455Protected
456 Sub _Initialize ( id As DWord )
457 This.id = id
458 End Sub
459
460Public 'Property
461 'スティックの動きの閾値を設定
462 Sub Threshold ( value As DWord )
463 joySetThreshold(id,value)
464 End Sub
465
466 'スティックの動きの閾値を取得
467 Function Threshold () As DWord
468 joyGetThreshold(id,Threshold)
469 End Function
470
471Public 'Method
472 'ジョイステックの性能を取得
473 Function GetCapabilities () As JoyCaps
474 Return New Detail._System_JoyCaps(This.id)
475 End Function
476
477 'ジョイステックの現在の状態を取得
478 Function GetInfo() As JoyInfo
479 Return New Detail._System_JoyInfo(This.id)
480 End Function
481
482 'キャプチャを開始
483 Sub SetCupture ( hwnd As HWND, period As DWord, changed As Boolean)
484 joySetCapture(hwnd,id,period,changed)
485 End Sub
486
487 'キャプチャを終了
488 Sub ReleaseCapture()
489 joyReleaseCapture(id)
490 End Sub
491End Class
492
493
494'ジョイスティックデバイスを取得するためのクラス
495Class Joystick
496Public 'Static Constant
497 Static Const Joystick1 = 0
498 Static Const Joystick2 = 1
499
500Public 'Static Property
501 'ドライバによってサポートされるジョイスティック数を取得
502 Static Function NumberOfDevices () As DWord
503 Return joyGetNumDevs()
504 End Function
505
506 '物理的に接続されたジョイスティック数を取得
507 Static Function NumberOfConnectedDevices () As DWord
508 Dim max = NumberOfDevices()
509 Dim cnt=0 As DWord
510 Dim info As JOYINFO
511 While joyGetPos(cnt,info) = JOYERR_NOERROR
512 cnt++
513 If cnt >= max Then Exit While
514 Wend
515 Return cnt
516 End Function
517
518Public 'Static Method
519 '使用可能なジョイスティックIDを列挙したIListを取得
520 Static Function GetJoystickIDs() As System.Collections.Generic.IList<DWord>
521 Dim max = NumberOfDevices()
522 GetJoystickIDs = New System.Collections.Generic.List<DWord>
523 Dim cnt As DWord
524 Dim info As JOYINFO
525 For cnt=0 To max-1
526 If joyGetPos(cnt,info) = JOYERR_NOERROR Then
527 GetJoystickIDs.Add(cnt)
528 End If
529 Next
530 End Function
531
532 '使用可能なジョイスティックデバイスを列挙したIListを取得
533 Static Function GetDevices() As System.Collections.Generic.IList<JoystickDevice>
534 Dim max = NumberOfDevices()
535 GetDevices = New System.Collections.Generic.List<JoystickDevice>
536 Dim cnt As DWord
537 Dim info As JOYINFO
538 For cnt=0 To max-1
539 If joyGetPos(cnt,info) = JOYERR_NOERROR Then
540 GetDevices.Add(GetDeviceFromID(cnt))
541 End If
542 Next
543 End Function
544
545 'ジョイスティックデバイスを取得
546 Static Function GetDeviceFromID( id As DWord ) As JoystickDevice
547 Return New Detail._System_JoystickDevice(id)
548 End Function
549
550End Class
551
552Namespace Detail
553Class _System_JoyCaps
554 Inherits JoyCaps
555Public
556 Sub _System_JoyCaps ( id As DWord )
557 This._Initialize(id)
558 End Sub
559
560 Override Function ToString () As String
561 Return "JoyCaps"
562 End Function
563End Class
564
565Class _System_JoyButtons
566 Inherits JoyButtons
567Public
568 Sub _System_JoyButtons ( dw As DWord )
569 This._Initialize(dw)
570 End Sub
571
572 Override Function ToString () As String
573 Return "JoyButtons"
574 End Function
575End Class
576
577Class _System_JoyPointOfView
578 Inherits JoyPointOfView
579Public
580 Sub _System_JoyPointOfView ( dw As DWord )
581 This._Initialize(dw)
582 End Sub
583
584 Override Function ToString () As String
585 Return "JoyPointOfView"
586 End Function
587End Class
588
589Class _System_JoyInfo
590 Inherits JoyInfo
591Public
592 Sub _System_JoyInfo ( id As DWord )
593 This._Initialize(id)
594 End Sub
595
596 Override Function ToString () As String
597 Return "JoyInfo"
598 End Function
599End Class
600
601Class _System_JoystickDevice
602 Inherits JoystickDevice
603Public
604 Sub _System_JoystickDevice ( id As DWord )
605 This._Initialize(id)
606 End Sub
607
608 Override Function ToString () As String
609 Return "Joystick"
610 End Function
611End Class
612
613End Namespace
614
615End Namespace
616End Namespace
617End Namespace
Note: See TracBrowser for help on using the repository browser.