Lite refactor/rename keys internal API

This commit is contained in:
Aaron Culliney 2019-03-10 12:17:06 -07:00
parent faf7d707ed
commit 9b110224a0
12 changed files with 129 additions and 159 deletions

View File

@ -243,16 +243,20 @@ void android_keycode_to_emulator(int keyCode, int metaState, bool pressed) {
} }
} while (0); } while (0);
if (key < 0) {
return;
}
//LOG("keyCode:%08x -> key:%02x ('%c') metaState:%08x", keyCode, key, key, metaState); //LOG("keyCode:%08x -> key:%02x ('%c') metaState:%08x", keyCode, key, key, metaState);
if (isASCII && _is_ctrl(metaState)) { if (isASCII && _is_ctrl(metaState)) {
key = c_keys_ascii_to_scancode(key); key = keys_ascii2Scancode(key);
c_keys_handle_input(key, true, false); keys_handleInput(key, /*is_pressed:*/true, /*is_ascii:*/false);
isASCII = false; isASCII = false;
pressed = false; pressed = false;
} }
assert(key < 0x80); assert(key < 0x80);
c_keys_handle_input(key, pressed, isASCII); keys_handleInput(key, pressed, isASCII);
} }

View File

@ -114,7 +114,7 @@
#ifdef KEYPAD_JOYSTICK #ifdef KEYPAD_JOYSTICK
if (joy_mode == JOY_KPAD) if (joy_mode == JOY_KPAD)
{ {
c_keys_handle_input(-1, 0, 0); keys_handleInput(/*scancode:*/-1, /*is_pressed:*/false, /*is_ascii:*/false);
} }
#endif #endif
} }

View File

@ -272,11 +272,11 @@ static void prefsChangeCallback(const char *domain)
{ {
case ALT_LT: case ALT_LT:
leftAltEngaged = !leftAltEngaged; leftAltEngaged = !leftAltEngaged;
c_keys_handle_input(SCODE_L_ALT, /*pressed:*/leftAltEngaged, /*cooked:*/0); keys_handleInput(SCODE_L_ALT, /*is_pressed:*/leftAltEngaged, /*is_ascii:*/false);
break; break;
case ALT_RT: case ALT_RT:
rightAltEngaged = !rightAltEngaged; rightAltEngaged = !rightAltEngaged;
c_keys_handle_input(SCODE_R_ALT, /*pressed:*/rightAltEngaged, /*cooked:*/0); keys_handleInput(SCODE_R_ALT, /*is_pressed:*/rightAltEngaged, /*is_ascii:*/false);
break; break;
default: default:
break; break;
@ -298,16 +298,16 @@ static void prefsChangeCallback(const char *domain)
switch (scode) switch (scode)
{ {
case NSUpArrowFunctionKey: case NSUpArrowFunctionKey:
c_keys_handle_input(SCODE_U, pressed, /*cooked:*/0); keys_handleInput(SCODE_U, pressed, /*is_ascii:*/false);
break; break;
case NSDownArrowFunctionKey: case NSDownArrowFunctionKey:
c_keys_handle_input(SCODE_D, pressed, /*cooked:*/0); keys_handleInput(SCODE_D, pressed, /*is_ascii:*/false);
break; break;
case NSLeftArrowFunctionKey: case NSLeftArrowFunctionKey:
c_keys_handle_input(SCODE_L, pressed, /*cooked:*/0); keys_handleInput(SCODE_L, pressed, /*is_ascii:*/false);
break; break;
case NSRightArrowFunctionKey: case NSRightArrowFunctionKey:
c_keys_handle_input(SCODE_R, pressed, /*cooked:*/0); keys_handleInput(SCODE_R, pressed, /*is_ascii:*/false);
break; break;
default: default:
break; break;

View File

@ -252,27 +252,27 @@
} }
case SHIFT_LT: case SHIFT_LT:
c_keys_handle_input(SCODE_L_SHIFT, ([event modifierFlags] & NSShiftKeyMask), 0); keys_handleInput(SCODE_L_SHIFT, /*is_pressed:*/([event modifierFlags] & NSShiftKeyMask), /*is_ascii:*/false);
break; break;
case SHIFT_RT: case SHIFT_RT:
c_keys_handle_input(SCODE_R_SHIFT, ([event modifierFlags] & NSShiftKeyMask), 0); keys_handleInput(SCODE_R_SHIFT, /*is_pressed:*/([event modifierFlags] & NSShiftKeyMask), /*is_ascii:*/false);
break; break;
case CTRL_LT: case CTRL_LT:
c_keys_handle_input(SCODE_L_CTRL, ([event modifierFlags] & NSControlKeyMask), 0); keys_handleInput(SCODE_L_CTRL, /*is_pressed:*/([event modifierFlags] & NSControlKeyMask), /*is_ascii:*/false);
break; break;
case CTRL_RT: case CTRL_RT:
c_keys_handle_input(SCODE_R_CTRL, ([event modifierFlags] & NSControlKeyMask), 0); keys_handleInput(SCODE_R_CTRL, /*is_pressed:*/([event modifierFlags] & NSControlKeyMask), /*is_ascii:*/false);
break; break;
case ALT_LT: case ALT_LT:
c_keys_handle_input(SCODE_L_ALT, ([event modifierFlags] & NSAlternateKeyMask), 0); keys_handleInput(SCODE_L_ALT, /*is_pressed:*/([event modifierFlags] & NSAlternateKeyMask), /*is_ascii:*/false);
break; break;
case ALT_RT: case ALT_RT:
c_keys_handle_input(SCODE_R_ALT, ([event modifierFlags] & NSAlternateKeyMask), 0); keys_handleInput(SCODE_R_ALT, /*is_pressed:*/([event modifierFlags] & NSAlternateKeyMask), /*is_ascii:*/false);
break; break;
default: default:
@ -378,7 +378,7 @@
default: default:
if ([event modifierFlags] & NSControlKeyMask) if ([event modifierFlags] & NSControlKeyMask)
{ {
scode = c_keys_ascii_to_scancode(scode); scode = keys_ascii2Scancode(scode);
cooked = 0; cooked = 0;
} }
else else
@ -388,7 +388,7 @@
break; break;
} }
c_keys_handle_input(scode, pressed, cooked); keys_handleInput(scode, pressed, cooked);
} }
- (void)keyUp:(NSEvent *)event - (void)keyUp:(NSEvent *)event

View File

@ -15,8 +15,16 @@
#include "common.h" #include "common.h"
#define DEBUG_KEYS 0
#if DEBUG_KEYS
# define KEY_LOG(...) LOG(__VA_ARGS__)
#else
# define KEY_LOG(...)
#endif
static int next_key = -1; static int next_key = -1;
static int last_scancode = -1; static int last_scancode = -1;
bool caps_lock = true; // default enabled because so much breaks otherwise bool caps_lock = true; // default enabled because so much breaks otherwise
bool use_system_caps_lock = false; bool use_system_caps_lock = false;
@ -183,26 +191,24 @@ uint8_t keys_apple2ASCII(uint8_t c, OUTPARM font_mode_t *mode) {
} }
} }
int c_keys_ascii_to_scancode(int c) int keys_ascii2Scancode(uint8_t c) {
{
return scode_map[c&0x7f]; return scode_map[c&0x7f];
} }
int c_keys_is_shifted() bool keys_isShifted(void) {
{
return key_pressed[SCODE_L_SHIFT] || key_pressed[SCODE_R_SHIFT]; return key_pressed[SCODE_L_SHIFT] || key_pressed[SCODE_R_SHIFT];
} }
/* ------------------------------------------------------------------------- // ----------------------------------------------------------------------------
Handle input : keys and joystick. // Handle input, both for keys and joystick.
------------------------------------------------------------------------- */ //
void c_keys_handle_input(int scancode, int pressed, int is_cooked) // NOTE: `scancode` can be either a scancode or an ASCII key.
{ void keys_handleInput(int scancode, bool is_pressed, bool is_ascii) {
int *keymap = NULL; KEY_LOG("keys ... scancode:%d is_pressed:%d is_ascii:%d", scancode, is_pressed, is_ascii);
if (is_cooked) { if (is_ascii) {
last_scancode = -1; last_scancode = -1;
if (!pressed) { if (!is_pressed) {
return; return;
} }
if (! (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]) ) { if (! (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]) ) {
@ -215,57 +221,45 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
assert(scancode < 0x80); assert(scancode < 0x80);
last_scancode = scancode; last_scancode = scancode;
int *keymap = NULL;
if ((key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) && if ((key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) &&
(key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ])) (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]))
{ {
keymap = apple_iie_keymap_shift_ctrl; keymap = apple_iie_keymap_shift_ctrl;
} } else if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]) {
else if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ])
{
keymap = apple_iie_keymap_ctrl; keymap = apple_iie_keymap_ctrl;
} } else if (key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) {
else if (key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ])
{
keymap = apple_iie_keymap_shifted; keymap = apple_iie_keymap_shifted;
} } else if (caps_lock) {
else if (caps_lock)
{
keymap = apple_iie_keymap_caps; keymap = apple_iie_keymap_caps;
} } else {
else
{
keymap = apple_iie_keymap_plain; keymap = apple_iie_keymap_plain;
} }
if (pressed) if (is_pressed) {
{
key_pressed[ scancode ] = 1; key_pressed[ scancode ] = 1;
switch (keymap[ scancode ]) switch (keymap[ scancode ]) {
{ case JB0:
case JB0: run_args.joy_button0 = 0xff; /* open apple */
run_args.joy_button0 = 0xff; /* open apple */ break;
break; case JB1:
case JB1: run_args.joy_button1 = 0xff; /* closed apple */
run_args.joy_button1 = 0xff; /* closed apple */ break;
break; default:
default: next_key = keymap[ scancode ];
next_key = keymap[scancode]; break;
break;
} }
} } else {
else
{
key_pressed[ scancode ] = 0; key_pressed[ scancode ] = 0;
switch (keymap[ scancode ]) switch (keymap[ scancode ]) {
{ case JB0:
case JB0: run_args.joy_button0 = 0x00;
run_args.joy_button0 = 0x00; break;
break; case JB1:
case JB1: run_args.joy_button1 = 0x00;
run_args.joy_button1 = 0x00; break;
break; default:
default: break;
break;
} }
} }
} }
@ -282,16 +276,14 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
int current_key = next_key; int current_key = next_key;
next_key = -1; next_key = -1;
if (current_key < 128) if (current_key < 0x80) {
{
apple_ii_64k[0][0xC000] = current_key | 0x80; apple_ii_64k[0][0xC000] = current_key | 0x80;
apple_ii_64k[1][0xC000] = current_key | 0x80; apple_ii_64k[1][0xC000] = current_key | 0x80;
break; break;
} }
#ifdef INTERFACE_CLASSIC #ifdef INTERFACE_CLASSIC
if (current_key == kF9) if (current_key == kF9) {
{
cpu_pause(); cpu_pause();
timing_toggleCPUSpeed(); timing_toggleCPUSpeed();
cpu_resume(); cpu_resume();
@ -367,18 +359,15 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
} }
#endif #endif
if (current_key == kEND) if (current_key == kEND) {
{ if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]) {
if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ])
{
cpu65_interrupt(ResetSig); cpu65_interrupt(ResetSig);
} }
break; break;
} }
#ifdef INTERFACE_CLASSIC #ifdef INTERFACE_CLASSIC
if ( c_keys_is_interface_key(current_key) || (current_key == kPAUSE) ) if ( c_keys_is_interface_key(current_key) || (current_key == kPAUSE) ) {
{
c_interface_begin(current_key); c_interface_begin(current_key);
} }
#endif #endif
@ -388,8 +377,7 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
#ifdef KEYPAD_JOYSTICK #ifdef KEYPAD_JOYSTICK
// Keypad emulated joystick relies on "raw" keyboard input // Keypad emulated joystick relies on "raw" keyboard input
if (joy_mode == JOY_KPAD) if (joy_mode == JOY_KPAD) {
{
bool joy_x_axis_unpressed = !( key_pressed[SCODE_KPAD_L] || key_pressed[SCODE_KPAD_R] || bool joy_x_axis_unpressed = !( key_pressed[SCODE_KPAD_L] || key_pressed[SCODE_KPAD_R] ||
key_pressed[SCODE_KPAD_UL] || key_pressed[SCODE_KPAD_DL] || key_pressed[SCODE_KPAD_UR] || key_pressed[SCODE_KPAD_DR] || key_pressed[SCODE_KPAD_UL] || key_pressed[SCODE_KPAD_DL] || key_pressed[SCODE_KPAD_UR] || key_pressed[SCODE_KPAD_DR] ||
// and allow regular PC arrow keys to manipulate joystick... // and allow regular PC arrow keys to manipulate joystick...
@ -398,8 +386,7 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
key_pressed[SCODE_KPAD_UL] || key_pressed[SCODE_KPAD_DL] || key_pressed[SCODE_KPAD_UR] || key_pressed[SCODE_KPAD_DR] || key_pressed[SCODE_KPAD_UL] || key_pressed[SCODE_KPAD_DL] || key_pressed[SCODE_KPAD_UR] || key_pressed[SCODE_KPAD_DR] ||
key_pressed[SCODE_U] || key_pressed[SCODE_D]); key_pressed[SCODE_U] || key_pressed[SCODE_D]);
if (key_pressed[ SCODE_KPAD_C ]) if (key_pressed[ SCODE_KPAD_C ]) {
{
joy_x = HALF_JOY_RANGE; joy_x = HALF_JOY_RANGE;
joy_y = HALF_JOY_RANGE; joy_y = HALF_JOY_RANGE;
} }
@ -427,50 +414,34 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
} }
} }
if (key_pressed[ SCODE_KPAD_UL ] || key_pressed[ SCODE_KPAD_U ] || key_pressed[ SCODE_KPAD_UR ] ||/* regular arrow up */key_pressed[ SCODE_U ]) if (key_pressed[ SCODE_KPAD_UL ] || key_pressed[ SCODE_KPAD_U ] || key_pressed[ SCODE_KPAD_UR ] ||/* regular arrow up */key_pressed[ SCODE_U ]) {
{ if (joy_y > joy_step) {
if (joy_y > joy_step)
{
joy_y -= joy_step; joy_y -= joy_step;
} } else {
else
{
joy_y = 0; joy_y = 0;
} }
} }
if (key_pressed[ SCODE_KPAD_DL ] || key_pressed[ SCODE_KPAD_D ] || key_pressed[ SCODE_KPAD_DR ] ||/* regular arrow dn */key_pressed[ SCODE_D ]) if (key_pressed[ SCODE_KPAD_DL ] || key_pressed[ SCODE_KPAD_D ] || key_pressed[ SCODE_KPAD_DR ] ||/* regular arrow dn */key_pressed[ SCODE_D ]) {
{ if (joy_y < JOY_RANGE - joy_step) {
if (joy_y < JOY_RANGE - joy_step)
{
joy_y += joy_step; joy_y += joy_step;
} } else {
else
{
joy_y = JOY_RANGE-1; joy_y = JOY_RANGE-1;
} }
} }
if (key_pressed[ SCODE_KPAD_UL ] || key_pressed[ SCODE_KPAD_L ] || key_pressed[ SCODE_KPAD_DL ] ||/* regular arrow l */key_pressed[ SCODE_L ]) if (key_pressed[ SCODE_KPAD_UL ] || key_pressed[ SCODE_KPAD_L ] || key_pressed[ SCODE_KPAD_DL ] ||/* regular arrow l */key_pressed[ SCODE_L ]) {
{ if (joy_x > joy_step) {
if (joy_x > joy_step)
{
joy_x -= joy_step; joy_x -= joy_step;
} } else {
else
{
joy_x = 0; joy_x = 0;
} }
} }
if (key_pressed[ SCODE_KPAD_UR ] || key_pressed[ SCODE_KPAD_R ] || key_pressed[ SCODE_KPAD_DR ] ||/* regular arrow r */key_pressed[ SCODE_R ]) if (key_pressed[ SCODE_KPAD_UR ] || key_pressed[ SCODE_KPAD_R ] || key_pressed[ SCODE_KPAD_DR ] ||/* regular arrow r */key_pressed[ SCODE_R ]) {
{ if (joy_x < JOY_RANGE - joy_step) {
if (joy_x < JOY_RANGE - joy_step)
{
joy_x += joy_step; joy_x += joy_step;
} } else {
else
{
joy_x = JOY_RANGE-1; joy_x = JOY_RANGE-1;
} }
} }
@ -478,12 +449,12 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
#endif #endif
} }
#ifdef INTERFACE_CLASSIC
int c_rawkey() int c_rawkey()
{ {
return last_scancode; return last_scancode;
} }
#ifdef INTERFACE_CLASSIC
int c_mygetch(int block) int c_mygetch(int block)
{ {
int retval; int retval;

View File

@ -138,15 +138,16 @@
extern bool caps_lock; extern bool caps_lock;
extern bool use_system_caps_lock; extern bool use_system_caps_lock;
#ifdef INTERFACE_CLASSIC
int c_mygetch(int block); int c_mygetch(int block);
int c_rawkey(void); int c_rawkey(void);
#ifdef INTERFACE_CLASSIC
void c_keys_set_key(int key); void c_keys_set_key(int key);
bool c_keys_is_interface_key(int key); bool c_keys_is_interface_key(int key);
#endif #endif
int c_keys_is_shifted(void);
int c_keys_ascii_to_scancode(int ch); bool keys_isShifted(void);
void c_keys_handle_input(int scancode, int pressed, int is_cooked); int keys_ascii2Scancode(uint8_t ch);
void keys_handleInput(int scan_or_key, bool is_pressed, bool is_ascii);
uint8_t keys_apple2ASCII(uint8_t c, OUTPARM font_mode_t *mode); uint8_t keys_apple2ASCII(uint8_t c, OUTPARM font_mode_t *mode);

View File

@ -96,7 +96,7 @@ static void _glnode_updateGLUT(int unused) {
} }
#endif #endif
c_keys_handle_input(-1, 0, 0); keys_handleInput(/*scancode:*/-1, /*is_pressed:*/false, /*is_ascii:*/false);
glutPostRedisplay(); glutPostRedisplay();
glutTimerFunc(17, _glnode_updateGLUT, 0); glutTimerFunc(17, _glnode_updateGLUT, 0);
} }

View File

@ -142,7 +142,7 @@ static void touchkpad_keyboardReadCallback(void) {
#warning FIXME TODO : implement proper keyboard repeat callback timing #warning FIXME TODO : implement proper keyboard repeat callback timing
if (kpad.lastScancode >= 0) { if (kpad.lastScancode >= 0) {
c_keys_handle_input(kpad.lastScancode, /*pressed:*/false, /*ASCII:*/false); keys_handleInput(kpad.lastScancode, /*is_pressed:*/false, /*is_ascii:*/false);
kpad.lastScancode = -1; kpad.lastScancode = -1;
} }
@ -156,7 +156,7 @@ static void touchkpad_keyboardReadCallback(void) {
struct timespec deltat = timespec_diff(kpad.timingBegins[kpad.fireIdx], now, NULL); struct timespec deltat = timespec_diff(kpad.timingBegins[kpad.fireIdx], now, NULL);
if (deltat.tv_sec || deltat.tv_nsec > kpad.repeatThresholdNanos) { if (deltat.tv_sec || deltat.tv_nsec > kpad.repeatThresholdNanos) {
TOUCH_JOY_LOG("ACTIVE(%d,%d) REPEAT #%d/%lu/%lu: %d", kpad.axisLock, kpad.buttonLock, kpad.fireIdx, deltat.tv_sec, deltat.tv_nsec, scancode); TOUCH_JOY_LOG("ACTIVE(%d,%d) REPEAT #%d/%lu/%lu: %d", kpad.axisLock, kpad.buttonLock, kpad.fireIdx, deltat.tv_sec, deltat.tv_nsec, scancode);
c_keys_handle_input(scancode, /*pressed:*/true, /*ASCII:*/false); keys_handleInput(scancode, /*is_pressed:*/true, /*is_ascii:*/false);
kpad.lastScancode = scancode; kpad.lastScancode = scancode;
fired = kpad.fireIdx; fired = kpad.fireIdx;
} }
@ -225,13 +225,13 @@ static void touchkpad_resetState(void) {
for (unsigned int i=0; i<ROSETTE_COLS; i++) { for (unsigned int i=0; i<ROSETTE_COLS; i++) {
for (unsigned int j=0; j<ROSETTE_ROWS; j++) { for (unsigned int j=0; j<ROSETTE_ROWS; j++) {
c_keys_handle_input(kpad.rosetteScancodes[i], /*pressed:*/false, /*ASCII:*/false); keys_handleInput(kpad.rosetteScancodes[i], /*is_pressed:*/false, /*is_ascii:*/false);
} }
} }
c_keys_handle_input(kpad.touchDownScancode, /*pressed:*/false, /*ASCII:*/false); keys_handleInput(kpad.touchDownScancode, /*pressed:*/false, /*is_ascii:*/false);
c_keys_handle_input(kpad.northScancode, /*pressed:*/false, /*ASCII:*/false); keys_handleInput(kpad.northScancode, /*pressed:*/false, /*is_ascii:*/false);
c_keys_handle_input(kpad.southScancode, /*pressed:*/false, /*ASCII:*/false); keys_handleInput(kpad.southScancode, /*pressed:*/false, /*is_ascii:*/false);
} }
static void touchkpad_setup(void (*buttonDrawCallback)(char newChar)) { static void touchkpad_setup(void (*buttonDrawCallback)(char newChar)) {
@ -489,7 +489,7 @@ static void touchkpad_prefsChanged(const char *domain) {
kpad.repeatThresholdNanos = prefs_parseFloatValue(domain, PREF_KPAD_REPEAT_THRESH, &fVal) ? fVal*NANOSECONDS_PER_SECOND : NANOSECONDS_PER_SECOND; kpad.repeatThresholdNanos = prefs_parseFloatValue(domain, PREF_KPAD_REPEAT_THRESH, &fVal) ? fVal*NANOSECONDS_PER_SECOND : NANOSECONDS_PER_SECOND;
kpad.touchDownChar = prefs_parseLongValue (domain, PREF_KPAD_TOUCHDOWN_CHAR, &lVal, /*base:*/10) ? lVal : ICONTEXT_SPACE_VISUAL; kpad.touchDownChar = prefs_parseLongValue (domain, PREF_KPAD_TOUCHDOWN_CHAR, &lVal, /*base:*/10) ? lVal : ICONTEXT_SPACE_VISUAL;
kpad.touchDownScancode = prefs_parseLongValue (domain, PREF_KPAD_TOUCHDOWN_SCAN, &lVal, /*base:*/10) ? lVal : c_keys_ascii_to_scancode(' '); kpad.touchDownScancode = prefs_parseLongValue (domain, PREF_KPAD_TOUCHDOWN_SCAN, &lVal, /*base:*/10) ? lVal : keys_ascii2Scancode(' ');
kpad.southChar = prefs_parseLongValue (domain, PREF_KPAD_SWIPE_SOUTH_CHAR, &lVal, /*base:*/10) ? lVal : ICONTEXT_NONACTIONABLE; kpad.southChar = prefs_parseLongValue (domain, PREF_KPAD_SWIPE_SOUTH_CHAR, &lVal, /*base:*/10) ? lVal : ICONTEXT_NONACTIONABLE;
kpad.southScancode = prefs_parseLongValue (domain, PREF_KPAD_SWIPE_SOUTH_SCAN, &lVal, /*base:*/10) ? lVal : -1; kpad.southScancode = prefs_parseLongValue (domain, PREF_KPAD_SWIPE_SOUTH_SCAN, &lVal, /*base:*/10) ? lVal : -1;
@ -506,9 +506,9 @@ static void touchkpad_prefsChanged(const char *domain) {
ICONTEXT_NONACTIONABLE, 'M', ICONTEXT_NONACTIONABLE, ICONTEXT_NONACTIONABLE, 'M', ICONTEXT_NONACTIONABLE,
}; };
const int rosetteScans[ROSETTE_ROWS*ROSETTE_COLS] = { const int rosetteScans[ROSETTE_ROWS*ROSETTE_COLS] = {
-1, c_keys_ascii_to_scancode('I'), -1, -1, keys_ascii2Scancode('I'), -1,
c_keys_ascii_to_scancode('J'), -1, c_keys_ascii_to_scancode('K'), keys_ascii2Scancode('J'), -1, keys_ascii2Scancode('K'),
-1, c_keys_ascii_to_scancode('M'), -1, -1, keys_ascii2Scancode('M'), -1,
}; };
for (unsigned long i=0; i<rosetteCount; i++) { for (unsigned long i=0; i<rosetteCount; i++) {
kpad.rosetteChars[i] = rosetteChars[i]; kpad.rosetteChars[i] = rosetteChars[i];

View File

@ -453,24 +453,24 @@ static inline int64_t _tap_key_at_point(float x, float y) {
assert(scancode < 0x80); assert(scancode < 0x80);
if (isASCII) { if (isASCII) {
assert(key < 0x80); assert(key < 0x80);
scancode = c_keys_ascii_to_scancode(key); scancode = keys_ascii2Scancode(key);
if (kbd.ctrlPressed) { if (kbd.ctrlPressed) {
c_keys_handle_input(scancode, /*pressed*/true, /*ASCII:*/false); keys_handleInput(scancode, /*is_pressed*/true, /*is_ascii:*/false);
c_keys_handle_input(scancode, /*pressed*/false, /*ASCII:*/false); keys_handleInput(scancode, /*is_pressed*/false, /*is_ascii:*/false);
} else { } else {
c_keys_handle_input(key, /*pressed:*/true, /*ASCII:*/true); keys_handleInput(key, /*is_pressed:*/true, /*is_ascii:*/true);
c_keys_handle_input(key, /*pressed:*/false, /*ASCII:*/true); keys_handleInput(key, /*is_pressed:*/false, /*is_ascii:*/true);
} }
if (key == ' ' && isCalibrating) { if (key == ' ' && isCalibrating) {
key = ICONTEXT_SPACE_VISUAL; key = ICONTEXT_SPACE_VISUAL;
} }
} else if (isCTRL) { } else if (isCTRL) {
assert(scancode == SCODE_L_CTRL); assert(scancode == SCODE_L_CTRL);
c_keys_handle_input(scancode, /*pressed:*/kbd.ctrlPressed, /*ASCII:*/false); keys_handleInput(scancode, /*is_pressed:*/kbd.ctrlPressed, /*is_ascii:*/false);
} else if (scancode) { } else if (scancode) {
// perform a press of other keys (ESC, Arrows, etc) // perform a press of other keys (ESC, Arrows, etc)
c_keys_handle_input(scancode, /*pressed:*/true, /*ASCII:*/false); keys_handleInput(scancode, /*is_pressed:*/true, /*is_ascii:*/false);
c_keys_handle_input(scancode, /*pressed:*/false, /*ASCII:*/false); keys_handleInput(scancode, /*is_pressed:*/false, /*is_ascii:*/false);
} }
// draw current selected key (if any) // draw current selected key (if any)
@ -979,7 +979,7 @@ static void gltouchkbd_applyPrefs(void) {
// reset CTRL pressed state upon leaving this touch device // reset CTRL pressed state upon leaving this touch device
kbd.ctrlPressed = false; kbd.ctrlPressed = false;
c_keys_handle_input(SCODE_L_CTRL, /*pressed:*/false, /*ASCII:*/false); keys_handleInput(SCODE_L_CTRL, /*is_pressed:*/false, /*is_ascii:*/false);
} }
char *kbdPath = NULL; char *kbdPath = NULL;

View File

@ -22,7 +22,7 @@ static inline void _capslock_hackaround(void) {
// NOTE : Unfortunately it appears that we cannot get a raw key down/up notification for CAPSlock, so hack that here // NOTE : Unfortunately it appears that we cannot get a raw key down/up notification for CAPSlock, so hack that here
// ALSO : Emulator initially sets CAPS state based on a user preference, but sync to system state if user changes it // ALSO : Emulator initially sets CAPS state based on a user preference, but sync to system state if user changes it
int modifiers = glutGetModifiers(); int modifiers = glutGetModifiers();
if (!c_keys_is_shifted()) { if (!keys_isShifted()) {
if (modifiers & GLUT_ACTIVE_SHIFT) { if (modifiers & GLUT_ACTIVE_SHIFT) {
use_system_caps_lock = true; use_system_caps_lock = true;
caps_lock = true; caps_lock = true;
@ -131,7 +131,7 @@ static int _glutkey_to_scancode(int key) {
break; break;
default: default:
key = c_keys_ascii_to_scancode(key); key = keys_ascii2Scancode(key);
break; break;
} }
@ -142,13 +142,13 @@ static int _glutkey_to_scancode(int key) {
void gldriver_on_key_down(unsigned char key, int x, int y) { void gldriver_on_key_down(unsigned char key, int x, int y) {
_capslock_hackaround(); _capslock_hackaround();
//LOG("onKeyDown %02x(%d)'%c'", key, key, key); //LOG("onKeyDown %02x(%d)'%c'", key, key, key);
c_keys_handle_input(key, 1, 1); keys_handleInput(key, /*is_pressed:*/true, /*is_ascii:*/true);
} }
void gldriver_on_key_up(unsigned char key, int x, int y) { void gldriver_on_key_up(unsigned char key, int x, int y) {
_capslock_hackaround(); _capslock_hackaround();
//LOG("onKeyUp %02x(%d)'%c'", key, key, key); //LOG("onKeyUp %02x(%d)'%c'", key, key, key);
c_keys_handle_input(key, 0, 1); keys_handleKnput(key, /*is_pressed:*/false, /*is_ascii:*/true);
} }
void gldriver_on_key_special_down(int key, int x, int y) { void gldriver_on_key_special_down(int key, int x, int y) {
@ -158,14 +158,14 @@ void gldriver_on_key_special_down(int key, int x, int y) {
glutFullScreenToggle(); glutFullScreenToggle();
} }
//LOG("onKeySpecialDown %08x(%d) -> %02X(%d)", key, key, scancode, scancode); //LOG("onKeySpecialDown %08x(%d) -> %02X(%d)", key, key, scancode, scancode);
c_keys_handle_input(scancode, 1, 0); keys_handleInput(scancode, /*is_pressed:*/true, /*is_ascii:*/false);
} }
void gldriver_on_key_special_up(int key, int x, int y) { void gldriver_on_key_special_up(int key, int x, int y) {
_capslock_hackaround(); _capslock_hackaround();
int scancode = _glutkey_to_scancode(key); int scancode = _glutkey_to_scancode(key);
//LOG("onKeySpecialDown %08x(%d) -> %02X(%d)", key, key, scancode, scancode); //LOG("onKeySpecialDown %08x(%d) -> %02X(%d)", key, key, scancode, scancode);
c_keys_handle_input(scancode, 0, 0); keys_handleInput(scancode, /*is_pressed:*/false, /*is_ascii:*/false);
} }
#define JOYSTICK_POLL_INTERVAL_MILLIS (ceilf(1000.f/60)) #define JOYSTICK_POLL_INTERVAL_MILLIS (ceilf(1000.f/60))

View File

@ -318,10 +318,10 @@ static void _nc_convertAppleGlyphs(INOUT chtype *c, OUTPARM char **s, uint8_t *c
} }
} }
static int _nc_keyToEmulator(int ncKey, int *isCooked) { static int _nc_keyToEmulator(int ncKey, bool *is_ascii) {
int a2key = ncKey; int a2key = ncKey;
bool isASCII = false; *is_ascii = false;
switch (ncKey) { switch (ncKey) {
case KEY_F(1): case KEY_F(1):
@ -388,14 +388,13 @@ static int _nc_keyToEmulator(int ncKey, int *isCooked) {
case ASCII_TAB: case ASCII_TAB:
default: default:
if (a2key >= 0 && a2key < 256) { if (a2key >= 0 && a2key < 256) {
isASCII = true; is_ascii = true;
} else { } else {
a2key = -1; a2key = -1;
} }
break; break;
} }
*isCooked = isASCII;
return a2key; return a2key;
} }
@ -548,18 +547,13 @@ static void ncvideo_main_loop(void) {
// handle keyboard input // handle keyboard input
int c = getch(); int c = getch();
int is_ascii = 0;
if (c == ERR) { if (c == ERR) {
c_keys_handle_input(-1, /*pressed:*/0, /*is_ascii:*/0); keys_handleInput(/*scancode:*/-1, /*is_pressed:*/false, /*is_ascii:*/false);
} else { } else {
bool is_ascii = false;
c = _nc_keyToEmulator(c, &is_ascii); c = _nc_keyToEmulator(c, &is_ascii);
keys_handleInput(/*scancode:*/c, /*is_pressed:*/true, is_ascii);
if (is_ascii) { keys_handleInput(/*scancode:*/c, /*is_pressed:*/false, is_ascii);
c_keys_handle_input(c, /*pressed:*/1, /*is_ascii:*/1);
} else {
c_keys_handle_input(c, /*pressed:*/1, /*is_ascii:*/0);
c_keys_handle_input(c, /*pressed:*/0, /*is_ascii:*/0);
}
} }
// FIXME TODO ... does not account for execution time drift // FIXME TODO ... does not account for execution time drift

View File

@ -406,19 +406,19 @@ void video_driver_sync(void) {
post_image(); post_image();
if (!XPending(display)) { if (!XPending(display)) {
c_keys_handle_input(/*scancode:*/-1, /*pressed:*/0, 0); keys_handleInput(/*scancode:*/-1, /*is_pressed:*/false, /*is_ascii:*/false);
} else { } else {
do { do {
XNextEvent(display, &xevent); XNextEvent(display, &xevent);
int scancode = -1; int scancode = -1;
int pressed = 0; bool is_pressed = false;
if (xevent.type == KeyPress || xevent.type == KeyRelease) { if (xevent.type == KeyPress || xevent.type == KeyRelease) {
scancode = keysym_to_scancode(); scancode = keysym_to_scancode();
pressed = (xevent.type == KeyPress); is_pressed = (xevent.type == KeyPress);
} }
c_keys_handle_input(scancode, pressed, 0); keys_handleInput(scancode, is_pressed, /*is_ascii:*/false);
} while (XPending(display)); } while (XPending(display));
} }
} }