Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/fceux.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorharry <hrosen2016@gmail.com>2022-08-22 05:43:35 +0300
committerharry <hrosen2016@gmail.com>2022-08-22 05:43:35 +0300
commit77b18ba9895bdfe3a7e2a5d2657c6024f36e479f (patch)
treed107e7a4a3f0b7da59c9fe330d2d1204dfdf5b68
parent7806b24388291a15b5cda04531c23ed417339ab7 (diff)
Added keyboard state feedback to lua input.get() function for Qt GUI. Returned key codes are slightly different but at least it does something. Issue #536.
-rw-r--r--src/drivers/Qt/input.cpp11
-rw-r--r--src/drivers/Qt/input.h3
-rw-r--r--src/lua-engine.cpp110
3 files changed, 122 insertions, 2 deletions
diff --git a/src/drivers/Qt/input.cpp b/src/drivers/Qt/input.cpp
index 5cd1f347..9bddbc7c 100644
--- a/src/drivers/Qt/input.cpp
+++ b/src/drivers/Qt/input.cpp
@@ -158,6 +158,15 @@ int getKeyState(int k)
return 0;
}
+const uint8_t *QtSDL_getKeyboardState( int *bufSize )
+{
+ if (bufSize != nullptr)
+ {
+ *bufSize = SDL_NUM_SCANCODES;
+ }
+ return g_keyState;
+}
+
//static int
//_keyonly(int a)
//{
@@ -1909,7 +1918,7 @@ static void UpdateFKB(void)
}
}
-const uint8 *getFamilyKeyboardState(void)
+const uint8_t *getFamilyKeyboardState(void)
{
return fkbkeys;
}
diff --git a/src/drivers/Qt/input.h b/src/drivers/Qt/input.h
index 023d41fe..8ed5ff38 100644
--- a/src/drivers/Qt/input.h
+++ b/src/drivers/Qt/input.h
@@ -148,7 +148,8 @@ int saveInputSettingsToFile( const char *fileBase = NULL );
int loadInputSettingsFromFile( const char *filename = NULL );
void toggleFamilyKeyboardFunc(void);
bool isFamilyKeyboardActv(void);
-const uint8 *getFamilyKeyboardState(void);
+const uint8_t *getFamilyKeyboardState(void);
+const uint8_t *QtSDL_getKeyboardState( int *bufSize );
#endif
diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp
index e5212fac..88950e61 100644
--- a/src/lua-engine.cpp
+++ b/src/lua-engine.cpp
@@ -54,6 +54,9 @@ extern TASEDITOR_LUA taseditor_lua;
#ifdef __SDL__
#ifdef __QT_DRIVER__
+#include "drivers/Qt/sdl.h"
+#include "drivers/Qt/main.h"
+#include "drivers/Qt/input.h"
#include "drivers/Qt/fceuWrapper.h"
#include "drivers/Qt/TasEditor/selection.h"
#include "drivers/Qt/TasEditor/laglog.h"
@@ -2638,6 +2641,113 @@ static int input_get(lua_State *L) {
}
}
}
+#elif defined(__QT_DRIVER__)
+ // Qt/SDL
+ {
+ const uint8_t *keyBuf = QtSDL_getKeyboardState(nullptr);
+
+ if (keyBuf)
+ {
+ int i=0;
+ char keyName[64];
+ const char *keyOut = nullptr;
+
+ for (int i=0; i<SDL_NUM_SCANCODES; i++)
+ {
+ if (keyBuf[i])
+ {
+ SDL_Keycode k = SDL_GetKeyFromScancode( static_cast<SDL_Scancode>(i) );
+
+ const char* name = SDL_GetKeyName(k);
+
+ //printf("Key:%i '%s'\n", i, name);
+
+ if ( isalpha(name[0]) || isdigit(name[0]) )
+ { // If name starts with letters or number, copy name without spaces
+ int ii=0, jj=0;
+ while (name[ii] != 0)
+ {
+ if ( isalpha(name[ii]) || isdigit(name[ii]) || (name[ii] == '_') )
+ {
+ keyName[jj] = name[ii]; jj++;
+ }
+ ii++;
+ }
+ keyName[jj] = 0;
+
+ keyOut = keyName;
+ }
+ else
+ { // Handle special char names
+ switch (name[0])
+ {
+ case '[':
+ keyOut = "LeftBracket";
+ break;
+ case ']':
+ keyOut = "RightBracket";
+ break;
+ case '{':
+ keyOut = "LeftBrace";
+ break;
+ case '}':
+ keyOut = "RightBrace";
+ break;
+ case ',':
+ keyOut = "Comma";
+ break;
+ case '.':
+ keyOut = "Period";
+ break;
+ case '~':
+ keyOut = "Tilde";
+ break;
+ case '`':
+ keyOut = "Backtick";
+ break;
+ case '|':
+ keyOut = "VerticalBar";
+ break;
+ case '/':
+ keyOut = "Slash";
+ break;
+ case '\\':
+ keyOut = "BackSlash";
+ break;
+ case '+':
+ keyOut = "Plus";
+ break;
+ case '=':
+ keyOut = "Equals";
+ break;
+ case '_':
+ keyOut = "Underscore";
+ break;
+ case '-':
+ keyOut = "Minus";
+ break;
+ case ';':
+ keyOut = "SemiColon";
+ break;
+ case ':':
+ keyOut = "Colon";
+ break;
+ case '\'':
+ case '\"':
+ keyOut = "Quote";
+ break;
+ default:
+ keyOut = name;
+ break;
+ }
+
+ }
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, keyOut);
+ }
+ }
+ }
+ }
#else
//SDL TODO: implement this for keyboard!!
#endif