Skip to content

Commit

Permalink
SDL2 keyboard entry : hitting PadStar, PadSlash, PadPlus, or PadMinus…
Browse files Browse the repository at this point in the history
… got you * followed by PADSTAR, / followed by PADSLASH, etc. Unfortunately, the first key was indistinguishable from a 'normal' asterisk/slash/etc. The only way to suppress the spurious keystroke I could see was to hold any of the offending four in abeyance for two milliseconds. If at the end of that time, we haven't received a PADx character, we can treat the *-/+ as 'real'. If we do receive a PADx character, we toss the *-/+ one. I think this is an SDL2 bug, and hope it's eventually fixed... but this workaround means PDCursesMod works even with defective SDL2.
  • Loading branch information
Bill-Gray committed Aug 19, 2022
1 parent 8a41f2e commit d87b7bd
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions sdl2/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ void PDC_set_keyboard_binary(bool on)

/* check if a key or mouse event is waiting */

static int _stored_key;
static Uint32 _stored_timestamp;

bool PDC_check_key(void)
{
bool haveevent;

if( _stored_key && SDL_GetTicks( ) > _stored_timestamp + 2)
return( TRUE);
PDC_pump_and_peep();

/* SDL_TEXTINPUT can return multiple chars from the IME which we
Expand Down Expand Up @@ -175,7 +180,6 @@ static int _handle_alt_keys(int key)
static int _process_key_event(void)
{
int i, key = 0;

#ifdef PDC_WIDE
size_t bytes;
#endif
Expand Down Expand Up @@ -226,6 +230,8 @@ static int _process_key_event(void)
}
else if (event.type == SDL_TEXTINPUT)
{
int rval;

#ifdef PDC_WIDE
if ((key = _utf8_to_unicode(event.text.text, &bytes)) == -1)
{
Expand All @@ -236,13 +242,20 @@ static int _process_key_event(void)
memmove(event.text.text, event.text.text + bytes,
strlen(event.text.text) - bytes + 1);
}
return _handle_alt_keys(key);
rval = _handle_alt_keys(key);
#else
key = (unsigned char)event.text.text[0];
memmove(event.text.text, event.text.text + 1,
strlen(event.text.text));
return key > 0x7f ? -1 : _handle_alt_keys(key);
rval = (key > 0x7f ? -1 : _handle_alt_keys(key));
#endif
if( strchr( "/+*-", rval)) /* may actually be PADSLASH, PADPLUS, */
{ /* etc. Wait 2 ms to see if a PADx */
_stored_key = rval; /* keystroke is coming in. */
_stored_timestamp = event.text.timestamp;
rval = -1;
}
return( rval);
}

oldkey = event.key.keysym.sym;
Expand Down Expand Up @@ -295,6 +308,7 @@ static int _process_key_event(void)
/* To get here, we ignore all other modifiers */
key = key_table[i].normal;
}
_stored_key = 0;

return key;
}
Expand Down Expand Up @@ -411,6 +425,14 @@ static int _process_mouse_event(void)

int PDC_get_key(void)
{
if( _stored_key && SDL_GetTicks( ) > _stored_timestamp + 2)
{ /* One of +/-* was hit and not cancelled */
const int key = _stored_key; /* out within 2 ms by a PADPLUS, */
/* PADSLASH, PADMINUS, or PADSTAR. */
_stored_key = 0;
return( key);
}

switch (event.type)
{
case SDL_QUIT:
Expand Down

0 comments on commit d87b7bd

Please sign in to comment.