Define a keyboard scan code for PrintScreen.

There is no real scan code for the PrintScreen key under DOS, but it
is convenient to be able to bind it as a screenshot key. Define a
"fake" scancode (126) to represent PrintScreen so that it can be
represented as a key binding in configuration files. Also add some
comments/notes to the scantokey[] lookup table.

This fixes #369.
This commit is contained in:
Simon Howard 2014-03-27 20:50:10 -04:00
parent 2b4eb0f8fb
commit 8a699c6ebc
4 changed files with 16 additions and 3 deletions

View file

@ -69,6 +69,7 @@
#define KEY_CAPSLOCK (0x80+0x3a)
#define KEY_NUMLOCK (0x80+0x45)
#define KEY_SCRLCK (0x80+0x46)
#define KEY_PRTSCR (0x80+0x59)
#define KEY_HOME (0x80+0x47)
#define KEY_END (0x80+0x4f)

View file

@ -480,7 +480,8 @@ static int TranslateKey(SDL_keysym *sym)
case SDLK_F10: return KEY_F10;
case SDLK_F11: return KEY_F11;
case SDLK_F12: return KEY_F12;
case SDLK_PRINT: return KEY_PRTSCR;
case SDLK_BACKSPACE: return KEY_BACKSPACE;
case SDLK_DELETE: return KEY_DEL;

View file

@ -1489,6 +1489,16 @@ static default_t *SearchCollection(default_collection_t *collection, char *name)
return NULL;
}
// Mapping from DOS keyboard scan code to internal key code (as defined
// in doomkey.h). I think I (fraggle) reused this from somewhere else
// but I can't find where. Anyway, notes:
// * KEY_PAUSE is wrong - it's in the KEY_NUMLOCK spot. This shouldn't
// matter in terms of Vanilla compatibility because neither of
// those were valid for key bindings.
// * There is no proper scan code for PrintScreen (on DOS machines it
// sends an interrupt). So I added a fake scan code of 126 for it.
// The presence of this is important so we can bind PrintScreen as
// a screenshot key.
static const int scantokey[128] =
{
0 , 27, '1', '2', '3', '4', '5', '6',
@ -1499,14 +1509,14 @@ static const int scantokey[128] =
'\'', '`', KEY_RSHIFT,'\\', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT,KEYP_MULTIPLY,
KEY_RALT, ' ', KEY_CAPSLOCK,KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_PAUSE,KEY_SCRLCK,KEY_HOME,
KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, /*KEY_NUMLOCK?*/KEY_PAUSE,KEY_SCRLCK,KEY_HOME,
KEY_UPARROW,KEY_PGUP,KEY_MINUS,KEY_LEFTARROW,KEYP_5,KEY_RIGHTARROW,KEYP_PLUS,KEY_END,
KEY_DOWNARROW,KEY_PGDN,KEY_INS,KEY_DEL,0, 0, 0, KEY_F11,
KEY_F12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, KEY_PRTSCR, 0
};

View file

@ -445,6 +445,7 @@ static int TranslateKey(SDL_keysym *sym)
case SDLK_F10: return KEY_F10;
case SDLK_F11: return KEY_F11;
case SDLK_F12: return KEY_F12;
case SDLK_PRINT: return KEY_PRTSCR;
case SDLK_BACKSPACE: return KEY_BACKSPACE;
case SDLK_DELETE: return KEY_DEL;