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.
This commit is contained in:
parent
7806b24388
commit
77b18ba989
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue