Android蓝牙手柄VA-013开发
VA-013简介
待补充
采用“X”+MODE开机方式,LED3灯亮模式
摇杆类变量
名 |
值 |
按键 |
MotionEvent.AXIS_BRAKE |
(Float)1/0 |
L2按下/松开(短按) |
MotionEvent.AXIS_GAS |
(Float)1/0 |
R2按下/松开(短按) |
MotionEvent.AXIS_HAT_Y |
(Float)-1/0/1 |
上键按下/松开/下键按下 |
MotionEvent.AXIS_HAT_X |
(Float)-1/0/1 |
左键按下/松开/右键按下 |
MotionEvent.AXIS_X |
(Float)-1~1 |
左摇杆X轴 |
MotionEvent.AXIS_Y |
(Float)-1~1 |
左摇杆Y轴 |
MotionEvent.AXIS_Z |
(Float)-1~1 |
右摇杆X轴 |
MotionEvent.AXIS_RZ |
(Float)-1~1 |
右摇杆Y轴 |
override fun onGenericMotionEvent(event: MotionEvent?): Boolean {
if (event != null){
var str:String
when {
event.getAxisValue(MotionEvent.AXIS_BRAKE) == 1.toFloat() -> {
str = "L2按下"
sendAndShowResetOrder()
}
event.getAxisValue(MotionEvent.AXIS_GAS) == 1.toFloat() -> {
str = "R2按下"
sendAndShowResetOrder()
}
event.getAxisValue(MotionEvent.AXIS_HAT_Y) == (-1).toFloat() -> {
str = "上键"
sendAndShowOrder(4,0)
}
event.getAxisValue(MotionEvent.AXIS_HAT_Y) == 1.toFloat() -> {
str = "下键"
sendAndShowOrder(4,1)
}
event.getAxisValue(MotionEvent.AXIS_HAT_X) == (-1).toFloat() -> {
str = "左键"
sendAndShowOrder(4,2)
}
event.getAxisValue(MotionEvent.AXIS_HAT_X) == 1.toFloat() -> {
str = "右键"
sendAndShowOrder(4,3)
}
else -> {
str = "左摇杆x:" + event.getAxisValue(MotionEvent.AXIS_X).toString() + ";y:" + event.getAxisValue(MotionEvent.AXIS_Y).toString() + " 右摇杆x" + event.getAxisValue(MotionEvent.AXIS_Z).toString() + ";y:" + event.getAxisValue(MotionEvent.AXIS_RZ).toString()
}
}
// msg.text = str
}
return true
}
按键类变量
keyCode |
按键 |
96 |
A键 |
97 |
B键 |
99 |
X |
100 |
Y |
102 |
L1 |
103 |
R1 |
104 |
L2(长按) |
105 |
R2(长按) |
106 |
左摇杆按下 |
107 |
右摇杆按下 |
108 |
START键 |
109 |
SELECT键 |
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
var str:String
when (keyCode) {
// 监控/拦截/屏蔽A方向键
96 ->{
str = "A键"
}
// 监控/拦截/屏蔽B方向键
97 ->{
str = "B键"
}
99 -> {
str = "X键"
}
100 ->{
str = "Y键"
}
102 ->{
str = "L1键"
}
103 ->{
str = "R1键"
}
// 长按触发,短按为 L2按下
104 ->{
str = "L2键"
}
// 长按触发,短按为 R2按下
105 ->{
str = "R2键"
}
106 ->{
str = "左摇杆按下键"
}
107 ->{
str = "右摇杆按下键"
}
108 ->{
str = "START键"
}
109 ->{
str = "SELECT键"
}
else -> str = "keyCode: $keyCode"
}
msg.text = str
return true
}