Game Development Reference
In-Depth Information
Also note that the Android key code must be mapped to a PC scan code and sent to the DSO using
the native interface class: Natives.sendNativeKeyEvent (event, scan code) . For more details on how
the controller works see the “Creating the Movement Controller” section.
Listing 6-8. Controller Events from the Main Activity
@Override
public void ControllerDown(int btnCode) {
switch (btnCode) {
case KeyEvent.KEYCODE_Y:
// strafe left
Natives.sendNativeKeyEvent(Natives.EV_KEYDOWN,
ScanCodes.sc_Alt);
Natives.sendNativeKeyEvent(Natives.EV_KEYDOWN,
ScanCodes.sc_LeftArrow);
break;
case KeyEvent.KEYCODE_X:
// strafe right
Natives.sendNativeKeyEvent(Natives.EV_KEYDOWN,
ScanCodes.sc_Alt);
Natives.sendNativeKeyEvent(Natives.EV_KEYDOWN,
ScanCodes.sc_RightArrow);
break;
case KeyEvent.KEYCODE_B:
// Fire
Natives.sendNativeKeyEvent(Natives.EV_KEYDOWN,
ScanCodes.sc_Control);
break;
case KeyEvent.KEYCODE_A:
// Rshift (Run)
Natives.sendNativeKeyEvent(Natives.EV_KEYDOWN,
ScanCodes.sc_RShift);
break;
default:
Natives.sendNativeKeyEvent(Natives.EV_KEYDOWN, ScanCodes
.keySymToScancode(btnCode));
break;
}
}
@Override
public void ControllerUp(int btnCode) {
switch (btnCode) {
case KeyEvent.KEYCODE_Y:
// strafe left
Natives.sendNativeKeyEvent(Natives.EV_KEYUP,
ScanCodes.sc_Alt);
Search WWH ::




Custom Search