Added code to differentiate left vs right modifier keys on windows and linux. Cannot do this yet on mac OSX.
This commit is contained in:
parent
187ee9646c
commit
5e6fd870fe
|
@ -114,6 +114,22 @@ else(WIN32)
|
|||
add_definitions( -D_USE_LIBAV ${LIBAV_CFLAGS} )
|
||||
endif()
|
||||
|
||||
#find_package(X11)
|
||||
pkg_check_modules( X11 x11)
|
||||
|
||||
if ( ${X11_FOUND} )
|
||||
message( STATUS "Has X11 Library ${X11_VERSION}" )
|
||||
add_definitions( -D_HAS_X11 )
|
||||
include_directories( ${X11_INCLUDE_DIR} )
|
||||
endif()
|
||||
|
||||
pkg_check_modules( XKB xkbcommon)
|
||||
|
||||
if ( ${XKB_FOUND} )
|
||||
message( STATUS "Has XKB Library ${XKB_VERSION}" )
|
||||
add_definitions( -D_HAS_XKB ${XKB_CFLAGS} )
|
||||
endif()
|
||||
|
||||
#pkg_check_modules( GL gl) # Use built in find package instead for OpenGL
|
||||
|
||||
# Check for OpenGL
|
||||
|
|
|
@ -110,6 +110,8 @@ consoleWin_t::consoleWin_t(QWidget *parent)
|
|||
//QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath);
|
||||
//printf("LibPath: '%s'\n", libpath.toStdString().c_str() );
|
||||
|
||||
printf("Running on Platform: %s\n", QGuiApplication::platformName().toStdString().c_str() );
|
||||
|
||||
QApplication::setStyle( new fceuStyle() );
|
||||
|
||||
initHotKeys();
|
||||
|
|
|
@ -1322,12 +1322,31 @@ UpdatePhysicalInput()
|
|||
// event.type, event.key.keysym.sym, event.key.keysym.scancode );
|
||||
|
||||
keyModifier = event.key.keysym.mod;
|
||||
g_keyState[SDL_SCANCODE_LSHIFT] = (event.key.keysym.mod & KMOD_LSHIFT) ? 1 : 0;
|
||||
g_keyState[SDL_SCANCODE_RSHIFT] = (event.key.keysym.mod & KMOD_RSHIFT) ? 1 : 0;
|
||||
g_keyState[SDL_SCANCODE_LALT] = (event.key.keysym.mod & KMOD_LALT) ? 1 : 0;
|
||||
g_keyState[SDL_SCANCODE_RALT] = (event.key.keysym.mod & KMOD_RALT) ? 1 : 0;
|
||||
g_keyState[SDL_SCANCODE_LCTRL] = (event.key.keysym.mod & KMOD_LCTRL) ? 1 : 0;
|
||||
g_keyState[SDL_SCANCODE_RCTRL] = (event.key.keysym.mod & KMOD_RCTRL) ? 1 : 0;
|
||||
|
||||
if ( (event.key.keysym.mod & KMOD_LSHIFT) == 0 )
|
||||
{
|
||||
g_keyState[SDL_SCANCODE_LSHIFT] = 0;
|
||||
}
|
||||
if ( (event.key.keysym.mod & KMOD_RSHIFT) == 0 )
|
||||
{
|
||||
g_keyState[SDL_SCANCODE_RSHIFT] = 0;
|
||||
}
|
||||
if ( (event.key.keysym.mod & KMOD_LALT) == 0 )
|
||||
{
|
||||
g_keyState[SDL_SCANCODE_LALT] = 0;
|
||||
}
|
||||
if ( (event.key.keysym.mod & KMOD_RALT) == 0 )
|
||||
{
|
||||
g_keyState[SDL_SCANCODE_RALT] = 0;
|
||||
}
|
||||
if ( (event.key.keysym.mod & KMOD_LCTRL) == 0 )
|
||||
{
|
||||
g_keyState[SDL_SCANCODE_LCTRL] = 0;
|
||||
}
|
||||
if ( (event.key.keysym.mod & KMOD_RCTRL) == 0 )
|
||||
{
|
||||
g_keyState[SDL_SCANCODE_RCTRL] = 0;
|
||||
}
|
||||
|
||||
g_keyState[event.key.keysym.scancode] = (event.type == SDL_KEYDOWN) ? 1 : 0;
|
||||
|
||||
|
|
|
@ -27,7 +27,39 @@
|
|||
|
||||
using namespace Qt;
|
||||
|
||||
SDL_Scancode convQtKey2SDLScanCode(Qt::Key q)
|
||||
#if defined(WIN32)
|
||||
|
||||
#include <windows.h>
|
||||
#include <winuser.h>
|
||||
static uint32_t ShiftKeyCodeR = VK_RSHIFT;
|
||||
static uint32_t CtrlKeyCodeR = VK_RCONTROL;
|
||||
static uint32_t AltKeyCodeR = VK_RMENU;
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
#if defined(_HAS_XKB)
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
static uint32_t ShiftKeyCodeR = XKB_KEY_Shift_R;
|
||||
static uint32_t CtrlKeyCodeR = XKB_KEY_Control_R;
|
||||
static uint32_t AltKeyCodeR = XKB_KEY_Alt_R;
|
||||
#elif defined(_HAS_X11)
|
||||
#include <X11/keysym.h>
|
||||
static uint32_t ShiftKeyCodeR = XK_Shift_R;
|
||||
static uint32_t CtrlKeyCodeR = XK_Control_R;
|
||||
static uint32_t AltKeyCodeR = XK_Alt_R;
|
||||
#else
|
||||
static uint32_t ShiftKeyCodeR = 0xffe2;
|
||||
static uint32_t CtrlKeyCodeR = 0xffe4;
|
||||
static uint32_t AltKeyCodeR = 0xffea;
|
||||
#endif
|
||||
|
||||
#else
|
||||
static uint32_t ShiftKeyCodeR = 0xffe2;
|
||||
static uint32_t CtrlKeyCodeR = 0xffe4;
|
||||
static uint32_t AltKeyCodeR = 0xffea;
|
||||
#endif
|
||||
|
||||
SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
|
||||
{
|
||||
SDL_Scancode s = SDL_SCANCODE_UNKNOWN;
|
||||
|
||||
|
@ -90,16 +122,37 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q)
|
|||
s = SDL_SCANCODE_PAGEDOWN;
|
||||
break;
|
||||
case Key_Shift:
|
||||
if ( nativeVirtualKey == ShiftKeyCodeR )
|
||||
{
|
||||
s = SDL_SCANCODE_RSHIFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SDL_SCANCODE_LSHIFT;
|
||||
}
|
||||
break;
|
||||
case Key_Control:
|
||||
if ( nativeVirtualKey == CtrlKeyCodeR )
|
||||
{
|
||||
s = SDL_SCANCODE_RCTRL;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SDL_SCANCODE_LCTRL;
|
||||
}
|
||||
break;
|
||||
case Key_Meta:
|
||||
s = SDL_SCANCODE_LGUI;
|
||||
break;
|
||||
case Key_Alt:
|
||||
if ( nativeVirtualKey == AltKeyCodeR )
|
||||
{
|
||||
s = SDL_SCANCODE_RALT;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SDL_SCANCODE_LALT;
|
||||
}
|
||||
break;
|
||||
case Key_CapsLock:
|
||||
s = SDL_SCANCODE_CAPSLOCK;
|
||||
|
@ -497,7 +550,7 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q)
|
|||
return s;
|
||||
}
|
||||
|
||||
SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q)
|
||||
SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
|
||||
{
|
||||
SDL_Keycode s = SDLK_UNKNOWN;
|
||||
|
||||
|
@ -562,16 +615,37 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q)
|
|||
s = SDLK_PAGEDOWN;
|
||||
break;
|
||||
case Key_Shift:
|
||||
if ( nativeVirtualKey == ShiftKeyCodeR )
|
||||
{
|
||||
s = SDLK_RSHIFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SDLK_LSHIFT;
|
||||
}
|
||||
break;
|
||||
case Key_Control:
|
||||
if ( nativeVirtualKey == CtrlKeyCodeR )
|
||||
{
|
||||
s = SDLK_RCTRL;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SDLK_LCTRL;
|
||||
}
|
||||
break;
|
||||
case Key_Meta:
|
||||
s = SDLK_LGUI;
|
||||
break;
|
||||
case Key_Alt:
|
||||
if ( nativeVirtualKey == AltKeyCodeR )
|
||||
{
|
||||
s = SDLK_RALT;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SDLK_LALT;
|
||||
}
|
||||
break;
|
||||
case Key_CapsLock:
|
||||
s = SDLK_CAPSLOCK;
|
||||
|
@ -1064,6 +1138,7 @@ int convKeyEvent2Sequence( QKeyEvent *event )
|
|||
int pushKeyEvent(QKeyEvent *event, int pressDown)
|
||||
{
|
||||
SDL_Event sdlev;
|
||||
uint32_t vkey;
|
||||
|
||||
if (pressDown)
|
||||
{
|
||||
|
@ -1076,12 +1151,15 @@ int pushKeyEvent(QKeyEvent *event, int pressDown)
|
|||
sdlev.key.state = SDL_RELEASED;
|
||||
}
|
||||
|
||||
sdlev.key.keysym.sym = convQtKey2SDLKeyCode((Qt::Key)event->key());
|
||||
vkey = event->nativeVirtualKey();
|
||||
|
||||
sdlev.key.keysym.sym = convQtKey2SDLKeyCode((Qt::Key)event->key(), vkey);
|
||||
|
||||
sdlev.key.keysym.scancode = SDL_GetScancodeFromKey(sdlev.key.keysym.sym);
|
||||
|
||||
//printf("Native ScanCode: x%08X %i \n", event->nativeScanCode(), event->nativeScanCode() );
|
||||
//printf("Scancode: 0x%08X %i \n", sdlev.key.keysym.scancode, sdlev.key.keysym.scancode );
|
||||
printf("Native ScanCode: x%08X %i \n", event->nativeScanCode(), event->nativeScanCode() );
|
||||
printf("Virtual ScanCode: x%08X %i \n", event->nativeVirtualKey(), event->nativeVirtualKey() );
|
||||
printf("Scancode: 0x%08X %i \n", sdlev.key.keysym.scancode, sdlev.key.keysym.scancode );
|
||||
|
||||
// SDL Docs say this code should never happen, but it does...
|
||||
// so force it to alternative scancode algorithm if it occurs.
|
||||
|
|
|
@ -48,9 +48,9 @@
|
|||
#include <QKeySequence>
|
||||
#include <SDL.h>
|
||||
|
||||
SDL_Keycode convQtKey2SDLKeyCode( Qt::Key q );
|
||||
SDL_Keycode convQtKey2SDLKeyCode( Qt::Key q, uint32_t nativeVirtualKey = 0 );
|
||||
|
||||
SDL_Scancode convQtKey2SDLScanCode( Qt::Key q );
|
||||
SDL_Scancode convQtKey2SDLScanCode( Qt::Key q, uint32_t nativeVirtualKey = 0 );
|
||||
|
||||
SDL_Keymod convQtKey2SDLModifier( Qt::KeyboardModifiers m );
|
||||
|
||||
|
|
Loading…
Reference in New Issue