RetroArch/input/drivers_keyboard/keyboard_event_win32.c

87 lines
2.7 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../general.h"
#include "../keyboard_line.h"
2015-04-09 03:16:02 +00:00
#include "../../gfx/common/win32_common.h"
#include "../input_common.h"
#include "../input_keymaps.h"
LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
unsigned scancode = (lparam >> 16) & 0xff;
unsigned keycode = input_keymaps_translate_keysym_to_rk(scancode);
2013-12-09 13:33:50 +00:00
uint16_t mod = 0;
if (GetKeyState(VK_SHIFT) & 0x80)
mod |= RETROKMOD_SHIFT;
if (GetKeyState(VK_CONTROL) & 0x80)
mod |= RETROKMOD_CTRL;
if (GetKeyState(VK_MENU) & 0x80)
mod |= RETROKMOD_ALT;
if (GetKeyState(VK_CAPITAL) & 0x81)
mod |= RETROKMOD_CAPSLOCK;
if (GetKeyState(VK_SCROLL) & 0x81)
mod |= RETROKMOD_SCROLLOCK;
if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x80)
mod |= RETROKMOD_META;
2013-12-09 13:33:50 +00:00
switch (message)
{
/* Seems to be hard to synchronize
* WM_CHAR and WM_KEYDOWN properly.
*/
case WM_CHAR:
2015-01-29 22:59:46 +00:00
input_keyboard_event(true, RETROK_UNKNOWN, wparam, mod,
RETRO_DEVICE_KEYBOARD);
return TRUE;
case WM_KEYDOWN:
/* DirectInput uses scancodes directly. */
2015-01-29 22:59:46 +00:00
input_keyboard_event(true, keycode, 0, mod,
RETRO_DEVICE_KEYBOARD);
return 0;
case WM_KEYUP:
/* DirectInput uses scancodes directly. */
2015-01-29 22:59:46 +00:00
input_keyboard_event(false, keycode, 0, mod,
RETRO_DEVICE_KEYBOARD);
return 0;
case WM_SYSKEYUP:
2015-01-29 22:59:46 +00:00
input_keyboard_event(false, keycode, 0, mod,
RETRO_DEVICE_KEYBOARD);
return 0;
case WM_SYSKEYDOWN:
2015-01-29 22:59:46 +00:00
input_keyboard_event(true, keycode, 0, mod,
RETRO_DEVICE_KEYBOARD);
switch (wparam)
{
case VK_F10:
case VK_MENU:
case VK_RSHIFT:
return 0;
}
break;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}