我目前正在使用具有客户端-服务器系统的游戏手柄/游戏控制器功能的 android 应用程序,其中客户端是 android,服务器是 PC 中的 java 桌面应用程序,蓝牙作为连接。到目前为止,我的应用程序仅使用 1 根手指(按住或单击)工作,现在我正在使用 2 根手指在事件按住按钮 A + 单击按钮 B 或按住按钮 A + 按住按钮 B 处使用多点触控。但我没有不知道如何在 android 上执行此操作,使用 mCommandService(BluetoothCommandService.valueOfButon) 将事件发送到 java,在 java 中读取按钮 B 已在按住按钮 A 时单击,并使用 robots.keyPress 执行值表示。
我实现了这个博客http://luugiathuy.com/2011/02/android-java-bluetooth/中的示例,用于 android 和 java 之间的蓝牙连接。这是我在 android 上的 onTouch 方法
public boolean onTouch(View v, MotionEvent event) {
switch(v.getId()){
case R.id.tombolL1:
cmd = BluetoothCommandService.aksi_l1;
break;
case R.id.tombolL2:
cmd = BluetoothCommandService.aksi_l2;
break;
case R.id.tombolR1:
cmd = BluetoothCommandService.aksi_r1;
break;
case R.id.tombolR2:
cmd = BluetoothCommandService.aksi_r2;
break;
case R.id.tombolAtas:
cmd = BluetoothCommandService.arah_atas;
break;
case R.id.tombolBawah:
cmd = BluetoothCommandService.arah_bawah;
break;
case R.id.tombolKiri:
cmd = BluetoothCommandService.arah_kiri;
break;
case R.id.tombolKanan:
cmd = BluetoothCommandService.arah_kanan;
break;
case R.id.tombolSegitiga:
cmd = BluetoothCommandService.aksi_segitiga;
break;
case R.id.tombolBulat:
cmd = BluetoothCommandService.aksi_bulat;
break;
case R.id.tombolSilang:
cmd = BluetoothCommandService.aksi_silang;
break;
case R.id.tombolKotak:
cmd = BluetoothCommandService.aksi_kotak;
break;
}
switch(action){
case MotionEvent.ACTION_DOWN:
handler1.removeCallbacks(mUpdateTask);
handler1.postAtTime(mUpdateTask, 200);
break;
case MotionEvent.ACTION_UP:
handler1.removeCallbacks(mUpdateTask);
break;
}
return false;
}
private Runnable mUpdateTask = new Runnable() {
@Override
public void run() {
mCommandService.write(cmd);
handler1.postAtTime(this, SystemClock.uptimeMillis() + 100);
//handler1.postAtTime(this, 200);
}
};
和java中的这个processCommand方法
private void processCommand(int command) {
try {
Robot robot = new Robot();
int key = 0;
switch(command){
case arah_atas:
key = KeyEvent.VK_UP;
break;
case arah_bawah:
key = KeyEvent.VK_DOWN;
break;
case arah_kiri:
key = KeyEvent.VK_LEFT;
break;
case arah_kanan:
key = KeyEvent.VK_RIGHT;
break;
case aksi_segitiga:
key = KeyEvent.VK_A;
break;
case aksi_bulat:
key = KeyEvent.VK_X;
break;
case aksi_silang:
key = KeyEvent.VK_Z;
break;
case aksi_kotak:
key = KeyEvent.VK_S;
break;
case aksi_l1:
key = KeyEvent.VK_Q;
break;
case aksi_l2:
key = KeyEvent.VK_W;
break;
case aksi_r1:
key = KeyEvent.VK_R;
break;
case aksi_r2:
key = KeyEvent.VK_E;
break;
case aksi_select:
key = KeyEvent.VK_SPACE;
break;
case aksi_start:
key = KeyEvent.VK_M;
break;
}
robot.keyPress(key);
Thread.sleep(50);
robot.keyRelease(key);
} catch (Exception e) {
e.printStackTrace();
}
}
请让我知道我该怎么做才能满足我的需要?