OSDN Git Service

[UI][Qt][Windows] Fix break widget when setting keyboard.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 9 Nov 2015 16:28:46 +0000 (01:28 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 9 Nov 2015 16:28:46 +0000 (01:28 +0900)
[UI][Qt]KEYBOARD: Fix wrong scan code assign.

source/src/common.h
source/src/qt/common/qt_gldraw.h
source/src/qt/common/qt_input.h
source/src/qt/gui/qt_input.cpp
source/src/vm/fm7/fm7_keyboard.h

index e02f1e1..305bd06 100644 (file)
 #include <process.h>
 #endif
 
-#if defined(_USE_AGAR) || defined(_USE_SDL)
-#include <SDL/SDL.h>
-#include <agar/core.h>
-#include <stdarg.h>
-#elif defined(_USE_QT)
+#if defined(_USE_QT)
 #include <SDL.h>
 #include <stdarg.h>
-# if defined(Q_OS_WIN32) || defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
+#include "qt_input.h"
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
 #  include <tchar.h>
 # endif
 # if defined(_USE_QT5)
@@ -79,7 +76,7 @@
 #  ifndef BOOL
    typedef int BOOL;
 #  endif
-# if !defined(Q_OS_WIN32) && !defined(Q_OS_WIN) && !defined(Q_OS_CYGWIN)
+# if !defined(Q_OS_CYGWIN) && !defined(Q_OS_WIN)
 #  ifndef BYTE
    typedef uint8_t BYTE;
 #  endif
@@ -92,7 +89,8 @@
 #  ifndef QWORD
    typedef uint64_t QWORD;
 #  endif
-
+# endif
+# if !defined(Q_OS_CYGWIN)
 #  ifndef UINT8
    typedef uint8_t UINT8;
 #  endif
    typedef int64_t INT64;
 #  endif
 
-//# ifndef Q_OS_WIN32
+# if !defined(Q_OS_CYGWIN) && !defined(Q_OS_WIN)
 static inline void _stprintf(char *s, const char *fmt, ...) {
    va_list args;
    
@@ -127,31 +125,22 @@ static inline void _stprintf(char *s, const char *fmt, ...) {
    sprintf(s, fmt, args);
    va_end(args);
 }
+# endif
 # define stricmp(a,b) strcmp(a,b)
 # define strnicmp(a,b,n) strncmp(a,b,n)
 
 
-// tchar.h
-//#  ifdef  _UNICODE
-//#    define __T(x)      L ## x
-//#  else
 #    define __T(x)      x
-//#  endif
  
 #  define _T(x)       __T(x)
 #  define _TEXT(x)    __T(x)
 
-//#  ifdef _UNICODE
-//    typedef wchar_t _TCHAR;
-//#  else
     typedef char    _TCHAR;
-//#  endif
 
+# if !defined(Q_OS_CYGWIN) && !defined(Q_OS_WIN)
 #  ifndef LPCTSTR
     typedef _TCHAR* LPCTSTR;
 #  endif
-
-
 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
    return strncpy((char *)d, (char *)s, n);
 }
@@ -160,14 +149,16 @@ static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
    return strncat((char *)d, (char *)s, n);
 }
 # endif
+
+# endif
 #endif
 
-#if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
+#if defined(_USE_QT)
 # if defined(Q_OS_CYGWIN)
 # define stricmp(a,b) strcmp(a,b)
 # define strnicmp(a,b,n) strncmp(a,b,n)
 # endif
-# if defined(Q_OS_WIN32) || defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
 
    typedef char    _TCHAR;
 # endif
@@ -184,18 +175,13 @@ static int DeleteFile(_TCHAR *path)
 }
 #include <algorithm>
 
-# ifndef Q_OS_WIN32
-#  ifdef USE_GETTEXT
-#  include <libintl.h>
-#  define _N(x) gettext(x)
-# else
+# ifndef Q_OS_WIN
 #  define _N(x) _T(x)
 # endif
-# endif
 #endif
 
-#if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
-# if defined(Q_OS_WIN32) || defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
+#if defined(_USE_QT)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
 #  include <tchar.h>
 # endif
 
@@ -481,7 +467,7 @@ typedef int errno_t;
 # endif
 //errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
-# if !defined(Q_OS_WIN32) && !defined(Q_OS_WIN) //&& !defined(Q_OS_CYGWIN)
+# if !defined(Q_OS_WIN) //&& !defined(Q_OS_CYGWIN)
 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
 # endif
index 2718bff..a5d3503 100644 (file)
@@ -130,8 +130,8 @@ class GLDrawClass: public QGLWidget
 # endif        
 
  protected:
-       struct NativeScanCode NativeScanCode[256];
-       struct NativeVirtualKeyCode NativeVirtualKeyCode[256];
+       struct NativeScanCode NativeScanCode[257];
+       struct NativeVirtualKeyCode NativeVirtualKeyCode[257];
 
        void keyReleaseEvent(QKeyEvent *event);
        void keyPressEvent(QKeyEvent *event);
index 67513fd..5b3fd70 100644 (file)
@@ -11,7 +11,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-# if !defined(Q_OS_CYGWIN)
+# if !defined(Q_OS_CYGWIN) && !defined(Q_OS_WIN)
    // Include from gui/drv_wgl_keymaps.h , libagar.
    enum {
        VK_LBUTTON = 0x01,
@@ -152,9 +152,7 @@ extern "C" {
        VK_OEM_CLEAR = 0xfe, 
 };
 # else
-#  if defined(Q_OS_CYGWIN)
 #      include <windows.h>
-#  endif  
 # endif
    
 #ifdef __cplusplus
index b742d33..e0abbfc 100644 (file)
@@ -49,7 +49,7 @@ const struct NativeScanCode convTable_QTScan106[] = {
        {VK_F12, 0x58},
        // Power, Sleep, Wake is not implemented, they are'nt safety.
        // Line 1
-       //{VK_KANJI, 49}, // Hankaku/Zenkaku
+       {VK_KANJI, 0x29}, // Hankaku/Zenkaku
        {'1', 0x02},
        {'2', 0x03},
        {'3', 0x04},
@@ -62,7 +62,7 @@ const struct NativeScanCode convTable_QTScan106[] = {
        {'0', 0x0b},
        {VK_OEM_MINUS, 0x0c}, // - =
        {VK_OEM_7, 0x0d}, // ^~
-       {VK_OEM_5, 0x7e}, // \|
+       {VK_OEM_5, 0x7d}, // \|
        {VK_BACK, 0x0e}, // Backspace
        // Line 2
        {VK_TAB, 0x0f},
@@ -80,7 +80,7 @@ const struct NativeScanCode convTable_QTScan106[] = {
        {VK_OEM_4, 0x1b}, // [
        {VK_RETURN, 0x1c}, // Enter (Full key)
        // Line 3
-       {VK_OEM_ATTN, 0x61}, // CAPS Lock
+       {VK_OEM_ATTN, 0x3a}, // CAPS Lock
        {'A', 0x1e},
        {'S', 0x1f},
        {'D', 0x20},
@@ -105,7 +105,7 @@ const struct NativeScanCode convTable_QTScan106[] = {
        {VK_OEM_COMMA, 0x33}, // ,
        {VK_OEM_PERIOD, 0x34}, // .
        {VK_OEM_2, 0x35}, // /(Slash)
-       {VK_OEM_102, 0x56}, //\_
+       {VK_OEM_102, 0x73}, //\_
        {VK_RSHIFT, 0x36},
        // Line 4
        {VK_LCONTROL, 0x1d},
@@ -114,7 +114,7 @@ const struct NativeScanCode convTable_QTScan106[] = {
        {VK_NONCONVERT, 0x68}, // Muhenkan
        {VK_SPACE, 0x39},
        {VK_CONVERT, 0x66}, // Henkan
-       {VK_OEM_COPY, 0x67}, // Katakana_Hiragana
+       {VK_OEM_COPY, 0x70}, // Katakana_Hiragana
        {VK_RMENU, 0x0138},
        {VK_RWIN,  0x015c},
        {VK_APPS, 0x015d},
@@ -146,11 +146,11 @@ const struct NativeScanCode convTable_QTScan106[] = {
        {VK_NUMPAD8, 0x48},
        {VK_NUMPAD9, 0x49},
        //
-       {VK_DECIMAL, 0x0145}, // NumLock     
+       {VK_DECIMAL, 0x53}, // NumLock     
        {VK_DIVIDE, 0x0135},
        {VK_MULTIPLY, 0x37},
-       {VK_SUBTRACT, 0x4e},
-       {VK_ADD, 0x4a},
+       {VK_SUBTRACT, 0x4a},
+       {VK_ADD, 0x4e},
        {VK_RETURN, 0x011c},  // Enter(ten Key)
        {0xffffffff, 0xffffffff}
 };
@@ -269,7 +269,7 @@ const struct NativeScanCode convTable_QTScan106[] = {
        {VK_NUMPAD8, 80},
        {VK_NUMPAD9, 81},
        //
-       {VK_DECIMAL, 77}, // NumLock     
+       {VK_DECIMAL, 0x005b}, // NumLock     
        {VK_DIVIDE, 106},
        {VK_MULTIPLY, 63},
        {VK_SUBTRACT, 82},
@@ -509,7 +509,7 @@ void GLDrawClass::initKeyCode(void)
                                uint32_t scan = nlist.at(1).toULong(&ok2, 16);
                                if((vk == 0) || (vk > 255)) continue;
                                if(ok1 && ok2) {
-                                       for(i = 0; i < 255; i++) {
+                                       for(i = 0; i < 256; i++) {
                                                if(NativeScanCode[i].vk == 0xffffffff) break;
                                                if(NativeScanCode[i].scan == scan) {
                                                        NativeScanCode[i].vk = (uint32_t)vk;
@@ -556,9 +556,9 @@ void GLDrawClass::initKeyCode(void)
                                if(nlist.count() < 2) continue;
                                uint32_t vk   = nlist.at(0).toULong(&ok1, 16);
                                uint32_t key  = nlist.at(1).toULong(&ok2, 16);
-                               if((vk == 0) || (vk > 255)) continue;
+                               if((vk == 0) || (vk > 256)) continue;
                                if(ok1 && ok2) {
-                                       for(i = 0; i < 255; i++) {
+                                       for(i = 0; i < 256; i++) {
                                                if(NativeVirtualKeyCode[i].vk == 0xffffffff) break;
                                                if(NativeVirtualKeyCode[i].key == key) {
                                                        NativeVirtualKeyCode[i].vk = (uint32_t)vk;
@@ -610,13 +610,8 @@ void GLDrawClass::keyReleaseEvent(QKeyEvent *event)
        uint32_t scan;
        uint32_t vk;
        if(event->isAutoRepeat()) return;
-//#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_MAC)
-//     scan = event->nativeVirtualKey();
-//     vk = getNativeKey2VK(scan);
-//#else   
        scan = event->nativeScanCode();
        vk = get106Scancode2VK(scan);
-//#endif
 #if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)  
 # if defined(NOTIFY_KEY_DOWN_LR_SHIFT)
        if(vk == VK_SHIFT) {
@@ -627,10 +622,6 @@ void GLDrawClass::keyReleaseEvent(QKeyEvent *event)
                if(GetAsyncKeyState(VK_LMENU) & 0x8000) vk = VK_LMENU;
                if(GetAsyncKeyState(VK_RMENU) & 0x8000) vk = VK_RMENU;
        }
-       if(vk == VK_CONTROL) {
-               if((GetAsyncKeyState(VK_LCONTROL) & 0x8000) == 0) vk = VK_LCONTROL;
-               if((GetAsyncKeyState(VK_RCONTROL) & 0x8000) == 0) vk = VK_RCONTROL;
-       }
 # endif
 #endif
        printf("Key: UP: VK=%d SCAN=%04x MOD=%08x\n", vk, scan, mod);
@@ -652,13 +643,8 @@ void GLDrawClass::keyPressEvent(QKeyEvent *event)
        uint32_t vk;
    
        if(event->isAutoRepeat()) return;
-//#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_MAC)
-//     scan = event->nativeVirtualKey();
-//     vk = getNativeKey2VK(scan);
-//#else   
        scan = event->nativeScanCode();
        vk = get106Scancode2VK(scan);
-//#endif
 
        if(vk == VK_APPS) { // Special key : capture/uncapture mouse.
                emit sig_toggle_mouse();
@@ -674,14 +660,10 @@ void GLDrawClass::keyPressEvent(QKeyEvent *event)
                if(GetAsyncKeyState(VK_LMENU) & 0x8000) vk = VK_LMENU;
                if(GetAsyncKeyState(VK_RMENU) & 0x8000) vk = VK_RMENU;
        }
-       if(vk == VK_CONTROL) {
-               if(GetAsyncKeyState(VK_LCONTROL) & 0x8000) vk = VK_LCONTROL;
-               if(GetAsyncKeyState(VK_RCONTROL) & 0x8000) vk = VK_RCONTROL;
-       }
 # endif
 #endif
    
-       printf("Key: DOWN: VK=%d SCAN=%04x MOD=%08x\n", vk, scan, mod);
+       //printf("Key: DOWN: VK=%d SCAN=%04x MOD=%08x\n", vk, scan, mod);
        emu->LockVM();
        emu->key_mod(mod);
        if(vk != 0) {
index cd99142..151aa8a 100644 (file)
@@ -16,9 +16,6 @@
 #include "../../fileio.h"
 
 #include "fm7_common.h"
-#if defined(_USE_QT)
-# include "qt_input.h"
-#endif
 
 #if defined(_FM77AV_VARIANTS)  
 class BEEP;