Map on-screen keys to mouse buttons

This commit is contained in:
Sergii Pylypenko
2014-10-11 03:01:46 +03:00
parent db084dcfd6
commit 3e4de48d10
6 changed files with 59 additions and 5 deletions

View File

@@ -264,7 +264,16 @@ class SDL_1_2_Keycodes
public static final int SDLK_EURO = 321;
public static final int SDLK_UNDO = 322;
public static final int SDLK_NO_REMAP = 512;
// Mouse buttons can be mapped to on-screen keys
public static final int SDLK_MOUSE_LEFT = 500;
public static final int SDLK_MOUSE_MIDDLE = 501;
public static final int SDLK_MOUSE_RIGHT = 502;
public static final int SDLK_MOUSE_WHEEL_UP = 503;
public static final int SDLK_MOUSE_WHEEL_DOWN = 504;
public static final int SDLK_MOUSE_X1 = 505;
public static final int SDLK_MOUSE_X2 = 506;
public static final int SDLK_NO_REMAP = 512;
}
// Autogenerated by hand with a command:
@@ -511,7 +520,16 @@ class SDL_1_3_Keycodes
public static final int SDLK_EJECT = 281;
public static final int SDLK_SLEEP = 282;
public static final int SDLK_NO_REMAP = 512;
// Mouse buttons can be mapped to on-screen keys
public static final int SDLK_MOUSE_LEFT = 500;
public static final int SDLK_MOUSE_MIDDLE = 501;
public static final int SDLK_MOUSE_RIGHT = 502;
public static final int SDLK_MOUSE_WHEEL_UP = 503;
public static final int SDLK_MOUSE_WHEEL_DOWN = 504;
public static final int SDLK_MOUSE_X1 = 505;
public static final int SDLK_MOUSE_X2 = 506;
public static final int SDLK_NO_REMAP = 512;
}
class SDL_Keys

View File

@@ -124,7 +124,7 @@ AppNeedsArrowKeys=y
# On-screen dpad/joystick will appear under finger when it touches the screen (y) or (n)
# Joystick always follows finger, so moving mouse requires touching the screen with other finger
FloatingScreenJoystick=y
FloatingScreenJoystick=n
# Application needs text input (y) or (n), enables button for text input on screen
AppNeedsTextInput=y

View File

@@ -170,6 +170,12 @@ extern void SDL_ANDROID_MainThreadPushKeyboardKey(int pressed, SDL_scancode key,
return;
}
if ( key >= SDLK_MOUSE_LEFT && key <= SDLK_MOUSE_X2 )
{
SDL_ANDROID_MainThreadPushMouseButton(pressed, key - SDLK_MOUSE_LEFT + SDL_BUTTON_LEFT);
return;
}
keysym.scancode = key;
if ( key < SDLK_LAST )
keysym.scancode = SDL_android_keysym_to_scancode[key];

View File

@@ -59,8 +59,21 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
/* JNI-C++ wrapper stuff */
// Special key to signal that key should be handled by Java internally, such as Volume Up/Down keys
#define SDLK_NO_REMAP 512
enum
{
// Mouse buttons can be mapped to on-screen keys
SDLK_MOUSE_LEFT = 500,
SDLK_MOUSE_MIDDLE = 501,
SDLK_MOUSE_RIGHT = 502,
SDLK_MOUSE_WHEEL_UP = 503,
SDLK_MOUSE_WHEEL_DOWN = 504,
SDLK_MOUSE_X1 = 505,
SDLK_MOUSE_X2 = 506,
// Special key to signal that key should be handled by Java internally, such as Volume Up/Down keys
SDLK_NO_REMAP = 512,
};
#define SDL_SCANCODE_NO_REMAP SDLK_NO_REMAP
#if SDL_VERSION_ATLEAST(1,3,0)

View File

@@ -211,6 +211,15 @@ KEYCODE_BUTTON_14 = 201,
KEYCODE_BUTTON_15 = 202,
KEYCODE_BUTTON_16 = 203,
// Press mouse buttons with keyboard events
KEYCODE_MOUSE_LEFT = 248,
KEYCODE_MOUSE_MIDDLE = 249,
KEYCODE_MOUSE_RIGHT = 250,
KEYCODE_MOUSE_WHEEL_UP = 251,
KEYCODE_MOUSE_WHEEL_DOWN= 252,
KEYCODE_MOUSE_X1 = 253,
KEYCODE_MOUSE_X2 = 254,
KEYCODE_LAST = 255 // Android 2.3 added several new gaming keys, Android 3.1 added even more - plz keep in sync with Keycodes.java
};

View File

@@ -241,6 +241,14 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)
keymap[KEYCODE_BUTTON_14] = SDL_KEY(N);
keymap[KEYCODE_BUTTON_15] = SDL_KEY(O);
keymap[KEYCODE_BUTTON_16] = SDL_KEY(P);
keymap[KEYCODE_MOUSE_LEFT] = SDL_KEY(MOUSE_LEFT);
keymap[KEYCODE_MOUSE_MIDDLE] = SDL_KEY(MOUSE_MIDDLE);
keymap[KEYCODE_MOUSE_RIGHT] = SDL_KEY(MOUSE_RIGHT);
keymap[KEYCODE_MOUSE_WHEEL_UP] = SDL_KEY(MOUSE_WHEEL_UP);
keymap[KEYCODE_MOUSE_WHEEL_DOWN] = SDL_KEY(MOUSE_WHEEL_DOWN);
keymap[KEYCODE_MOUSE_X1] = SDL_KEY(MOUSE_X1);
keymap[KEYCODE_MOUSE_X2] = SDL_KEY(MOUSE_X2);
}
unsigned char SDL_android_keysym_to_scancode[SDLK_LAST] = {