Add keyboard callback for Windows.

Only tested in Wine, but seems to work fine.
This commit is contained in:
Themaister 2013-12-09 14:22:46 +01:00
parent 3f8c892a0b
commit deadbbc906
6 changed files with 130 additions and 15 deletions

View File

@ -28,6 +28,7 @@ OBJ = frontend/frontend.o \
input/overlay.o \ input/overlay.o \
fifo_buffer.o \ fifo_buffer.o \
media/rarch.o \ media/rarch.o \
gfx/context/win32_common.o \
gfx/scaler/scaler.o \ gfx/scaler/scaler.o \
gfx/scaler/pixconv.o \ gfx/scaler/pixconv.o \
gfx/scaler/scaler_int.o \ gfx/scaler/scaler_int.o \

View File

@ -25,6 +25,7 @@
#include "../gfx_context.h" #include "../gfx_context.h"
#include "../gl_common.h" #include "../gl_common.h"
#include "../gfx_common.h" #include "../gfx_common.h"
#include "win32_common.h"
#include <windows.h> #include <windows.h>
#include <commdlg.h> #include <commdlg.h>
#include <string.h> #include <string.h>
@ -197,15 +198,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
} }
break; break;
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
switch (wparam) return win32_handle_keyboard_event(hwnd, message, wparam, lparam);
{
case VK_F10:
case VK_MENU:
case VK_RSHIFT:
return 0;
}
break;
case WM_CREATE: case WM_CREATE:
create_gl_context(hwnd); create_gl_context(hwnd);

View File

@ -0,0 +1,81 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
*
* 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 "../../input/input_common.h"
#include "win32_common.h"
LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message)
{
// Seems to be hard to synchronize WM_CHAR and WM_KEYDOWN properly.
case WM_CHAR:
{
if (g_extern.system.key_event)
g_extern.system.key_event(true, RETROK_UNKNOWN, wparam, 0); // TODO: Mod state
return TRUE;
}
case WM_KEYDOWN:
{
// DirectInput uses scancodes directly.
unsigned scancode = (lparam >> 16) & 0xff;
unsigned keycode = input_translate_keysym_to_rk(scancode);
if (g_extern.system.key_event)
g_extern.system.key_event(true, keycode, 0, 0); // TODO: Mod state
return 0;
}
case WM_KEYUP:
{
// DirectInput uses scancodes directly.
unsigned scancode = (lparam >> 16) & 0xff;
unsigned keycode = input_translate_keysym_to_rk(scancode);
if (g_extern.system.key_event)
g_extern.system.key_event(false, keycode, 0, 0); // TODO: Mod state
return 0;
}
case WM_SYSKEYUP:
{
unsigned scancode = (lparam >> 16) & 0xff;
unsigned keycode = input_translate_keysym_to_rk(scancode);
if (g_extern.system.key_event)
g_extern.system.key_event(false, keycode, 0, 0); // TODO: Mod state
return 0;
}
case WM_SYSKEYDOWN:
{
unsigned scancode = (lparam >> 16) & 0xff;
unsigned keycode = input_translate_keysym_to_rk(scancode);
if (g_extern.system.key_event)
g_extern.system.key_event(true, keycode, 0, 0); // TODO: Mod state
switch (wparam)
{
case VK_F10:
case VK_MENU:
case VK_RSHIFT:
return 0;
}
break;
}
}
return DefWindowProc(hwnd, message, wparam, lparam);
}

View File

@ -0,0 +1,32 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
*
* 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/>.
*/
#ifndef WIN32_COMMON_H__
#define WIN32_COMMON_H__
#ifdef __cplusplus
extern "C" {
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -32,6 +32,7 @@
#include "../gfx_common.h" #include "../gfx_common.h"
#include "../../compat/posix_string.h" #include "../../compat/posix_string.h"
#include "../../performance.h" #include "../../performance.h"
#include "../context/win32_common.h"
#include <iostream> #include <iostream>
#include <exception> #include <exception>
@ -83,14 +84,12 @@ namespace Callback
curD3D = (D3DVideo*)p_cs->lpCreateParams; curD3D = (D3DVideo*)p_cs->lpCreateParams;
break; break;
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
switch (wParam) return win32_handle_keyboard_event(hWnd, message, wParam, lParam);
{
case VK_F10:
case VK_RSHIFT:
return 0;
}
break;
case WM_DESTROY: case WM_DESTROY:
quit = true; quit = true;

View File

@ -750,6 +750,10 @@ struct retro_hw_render_callback
// keycode is the RETROK value of the char. // keycode is the RETROK value of the char.
// character is the text character of the pressed key. (UTF-32). // character is the text character of the pressed key. (UTF-32).
// key_modifiers is a set of RETROKMOD values or'ed together. // key_modifiers is a set of RETROKMOD values or'ed together.
// The pressed/keycode state can be indepedent of the character.
// It is also possible that multiple characters are generated from a single keypress.
// The events should be treated separately, however, when possible, the frontend should
// try to synchronize these.
typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers); typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
struct retro_keyboard_callback struct retro_keyboard_callback