GetKeyName and GetKeyScancode.
This commit is contained in:
63
src/core.c
63
src/core.c
@@ -1494,6 +1494,69 @@ int lcoreSetExitKey( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> keyName = RL_GetKeyName( int key, int scancode )
|
||||
|
||||
This function returns the name of the specified printable key, encoded as UTF-8.
|
||||
This is typically the character that key would produce without any modifier keys,
|
||||
intended for displaying key bindings to the user. For dead keys, it is typically
|
||||
the diacritic it would add to a character.
|
||||
|
||||
Do not use this function for text input. You will break text input for many
|
||||
languages even if it happens to work for yours.
|
||||
|
||||
If the key is KEY_UNKNOWN, the scancode is used to identify the key,
|
||||
otherwise the scancode is ignored. If you specify a non-printable key,
|
||||
or KEY_UNKNOWN and a scancode that maps to a non-printable key,
|
||||
this function returns nil but does not emit an error.
|
||||
|
||||
- Failure return -1
|
||||
- Success return string or nil
|
||||
*/
|
||||
int lcoreGetKeyName( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetKeyName( int key, int scancode )" );
|
||||
lua_pushinteger( L, -1 );
|
||||
return 1;
|
||||
}
|
||||
int scancode = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
int key = lua_tointeger( L, -1 );
|
||||
|
||||
const char *keyName = glfwGetKeyName( key, scancode );
|
||||
|
||||
if ( keyName != NULL ) {
|
||||
lua_pushstring( L, keyName );
|
||||
}
|
||||
else {
|
||||
lua_pushnil( L );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> scancode = RL_GetKeyScancode( int key )
|
||||
|
||||
This function returns the platform-specific scancode of the specified key.
|
||||
If the key is KEY_UNKNOWN or does not exist on the keyboard this method will return -1.
|
||||
|
||||
- Failure return nil
|
||||
- Success return int
|
||||
*/
|
||||
int lcoreGetKeyScancode( lua_State *L ) {
|
||||
if ( !lua_isnumber( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetKeyScancode( int key )" );
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
int scancode = glfwGetKeyScancode( lua_tointeger( L, -1 ) );
|
||||
|
||||
lua_pushinteger( L, scancode );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
## Core - Input-related Gamepad
|
||||
*/
|
||||
|
||||
@@ -58,6 +58,7 @@ void defineGlobals() {
|
||||
assignGlobalInt( LOG_FATAL, "LOG_FATAL" );
|
||||
assignGlobalInt( LOG_NONE, "LOG_NONE" );
|
||||
/* KeyboardKey */
|
||||
assignGlobalInt( GLFW_KEY_UNKNOWN, "KEY_UNKNOWN" );
|
||||
assignGlobalInt( KEY_NULL, "KEY_NULL" );
|
||||
assignGlobalInt( KEY_APOSTROPHE, "KEY_APOSTROPHE" );
|
||||
assignGlobalInt( KEY_COMMA, "KEY_COMMA" );
|
||||
@@ -798,6 +799,8 @@ void luaRegister() {
|
||||
lua_register( L, "RL_GetKeyPressed", lcoreGetKeyPressed );
|
||||
lua_register( L, "RL_GetCharPressed", lcoreGetCharPressed );
|
||||
lua_register( L, "RL_SetExitKey", lcoreSetExitKey );
|
||||
lua_register( L, "RL_GetKeyName", lcoreGetKeyName );
|
||||
lua_register( L, "RL_GetKeyScancode", lcoreGetKeyScancode );
|
||||
/* Input-related Gamepad. */
|
||||
lua_register( L, "RL_IsGamepadAvailable", lcoreIsGamepadAvailable );
|
||||
lua_register( L, "RL_IsGamepadButtonPressed", lcoreIsGamepadButtonPressed );
|
||||
|
||||
@@ -112,6 +112,7 @@ int ltextLoadFontFromImage( lua_State *L ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int firstChar = lua_tointeger( L, -1 );
|
||||
lua_pop( L, 1 );
|
||||
Color key = uluaGetColor( L );
|
||||
|
||||
Reference in New Issue
Block a user