Skip to content

Commit

Permalink
#558: Implemented automatic german keyboard detection
Browse files Browse the repository at this point in the history
This is a hack coming from WinUAE, hopefully gets the job done however
  • Loading branch information
midwan committed Feb 7, 2021
1 parent e906a52 commit 7592d00
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,9 @@ void process_event(SDL_Event event)
if ((amiberry_options.rctrl_as_ramiga || currprefs.right_control_is_right_win_key)
&& scancode == SDL_SCANCODE_RCTRL)
{
scancode = SDL_SCANCODE_RGUI;
scancode = SDL_SCANCODE_RGUI;
}

scancode = keyhack(scancode, pressed, 0);
my_kbd_handler(0, scancode, pressed, false);
}
return;
Expand All @@ -1151,7 +1151,7 @@ void process_event(SDL_Event event)
{
scancode = SDL_SCANCODE_RGUI;
}

scancode = keyhack(scancode, pressed, 0);
my_kbd_handler(0, scancode, pressed, true);
}
break;
Expand Down
69 changes: 69 additions & 0 deletions src/osdep/amiberry_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,75 @@ const char* remap_key_map_list_strings[] = {
const int remap_key_map_list_size = sizeof remap_key_map_list / sizeof remap_key_map_list[0];
static int keyboard_german;

int keyhack (int scancode, int pressed, int num)
{
static unsigned char backslashstate, apostrophstate;
const Uint8* state = SDL_GetKeyboardState(NULL);

// release mouse if TAB and ALT is pressed
if (pressed && state[SDL_SCANCODE_LALT] && scancode == SDL_SCANCODE_TAB) {
disablecapture();
return -1;
}

if (!keyboard_german)
return scancode;

if (scancode == SDL_SCANCODE_BACKSLASH)
{
if (state[SDL_SCANCODE_LSHIFT] || state[SDL_SCANCODE_RSHIFT] || apostrophstate)
{
if (pressed)
{
apostrophstate = 1;
inputdevice_translatekeycode(num, SDL_SCANCODE_RSHIFT, 0, false);
inputdevice_translatekeycode(num, SDL_SCANCODE_LSHIFT, 0, false);
return SDL_SCANCODE_APOSTROPHE; // the german ' key
}
else
{
apostrophstate = 0;
inputdevice_translatekeycode(num, SDL_SCANCODE_LALT, 0, true);
inputdevice_translatekeycode(num, SDL_SCANCODE_LSHIFT, 0, true);
inputdevice_translatekeycode(num, SDL_SCANCODE_3, 0, true); // release also the # key
return SDL_SCANCODE_APOSTROPHE;
}

}
if (pressed)
{
inputdevice_translatekeycode(num, SDL_SCANCODE_LALT, 1, false);
inputdevice_translatekeycode(num, SDL_SCANCODE_LSHIFT, 1, false);
return SDL_SCANCODE_3; // the german # key
}
else
{
inputdevice_translatekeycode(num, SDL_SCANCODE_LALT, 0, true);
inputdevice_translatekeycode(num, SDL_SCANCODE_LSHIFT, 0, true);
return SDL_SCANCODE_3; // the german # key

}
}
if (state[SDL_SCANCODE_RALT] || backslashstate) {
switch (scancode)
{
case SDL_SCANCODE_BACKSLASH: // WinUAE had 12 here -> is this the correct scancode?
if (pressed)
{
backslashstate = 1;
inputdevice_translatekeycode(num, SDL_SCANCODE_LALT, 0, true);
return SDL_SCANCODE_BACKSLASH;
}
else
{
backslashstate = 0;
return SDL_SCANCODE_BACKSLASH;
}
}
}
return scancode;
}

static void cleardid(struct didata* did)
{
memset(did, 0, sizeof(*did));
Expand Down
1 change: 1 addition & 0 deletions src/osdep/amiberry_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ extern const char* remap_key_map_list_strings[];
extern const int remap_key_map_list_size;

//extern bool key_used_by_retroarch_joy(int scancode);
extern int keyhack(int scancode, int pressed, int num);
extern int get_retroarch_kb_num();
extern bool init_kb_from_retroarch(int index, char* retroarch_file);
extern std::string sanitize_retroarch_name(std::string s);
Expand Down

0 comments on commit 7592d00

Please sign in to comment.