|
PS2 GamePad 模組的功能非常有彈性,除了有兩組類比搖桿的 x,y 軸輸出,
其他的按鈕更可以任意組合(組合鍵可參考PS2搖桿控制模組組合鍵應用),下面程式提供給剛入手此模組的初學者一個參考範例,希望能幫上忙。
Peripheral Ps As GamePadPs @ 31
Dim b4Way As Word
Dim wStatus,wKeyStatus As Word
Dim POSx,POSy,P_x,P_y As Integer
Sub MAIN()
Ps2Set()
wKeyStatus = 0
Do
'Debug CSRXY(1,1),"編碼後的鍵碼為:",wKeyStatus,CLREOL
Debug CSRXY(1,3),"左搖桿X座標:",POSx,CLREOL
Debug CSRXY(1,4),"左搖桿Y座標:",POSy,CLREOL
Select Case wKeyStatus
Case 1 : Program01() '三角
Case 2 ': Program02() '圓
Case 4 ': Program03() '×
Case 8 ': Program04() '方塊
Case 16 ': Program05() 'L1
Case 32 ': Program06() 'R1
Case 64 ': Program07() 'L2
Case 128 ': Program08() 'R2
Case 256 ': Program09() 'Select
Case 512 ': Program10() 'Start
Case 1024 ': Program11() 'LeftStick
Case 2048 ': Program12() 'RightStick
Case 4096 ': Program13() '右
Case 8192 ': Program14() '下
Case 16384 ': Program15() '左
Case 32768 ': Program16() '上
Case Else ': Program17() 'G_Test()
End Select
Loop
End Sub
'========================副程式區=========================
Sub Program01()
Debug CSRXY(1,2),"你按了三角形鍵!",CLREOL
Pause 2000
Debug CLS
End Sub
'===================PS2搖桿副程式區====================
Sub Ps2Set()
Ps.SetLStickDeadZone(1,5) 'SetDeadZone
Ps.SetRStickDeadZone(1,5) 'SetDeadZone
Ps.SetAnalog(1)
Ps.SetStickRefreshRate(10)
ps.EnableLStickEvent()
ps.EnableRStickEvent()
Ps.EnableDir4WayEvent() 'Enable Dir4Way
Ps.EnableKeyPressedEvent() 'Enable Pressed
Ps.EnableKeyReleasedEvent() 'Enable Pressed
End Sub
Event Ps.LStickEvent()
Ps.GetLXYPos(POSx,POSy)
End Event
Event Ps.RStickEvent()
Ps.GetRXYPos(P_x,P_y)
End Event
Event Ps.Dir4WayEvent()
Ps.GetDir4Way(b4Way)
Select Case b4Way
Case 1 : b4way = 1
Case 2 : b4way = 2
Case 3 : b4Way = 4
Case 4 : b4Way = 8
End Select
wKeyStatus = b4Way*4096 + wStatus
End Event
Event Ps.KeyPressedEvent()
wStatus = Ps.GetKeyStatus()
wKeyStatus = wStatus +b4Way*4096
End Event
Event Ps.KeyReleasedEvent()
wStatus = Ps.GetKeyStatus()
wKeyStatus = wStatus +b4Way*4096
End Event
|
|