mirror of
https://github.com/airstruck/luigi.git
synced 2025-11-18 12:25:06 +00:00
Scancodes exposed to KeyPress and KeyRelease events. (#54)
This commit is contained in:
committed by
airstruck
parent
709c012b43
commit
aa7d02b757
@@ -86,10 +86,12 @@ Backend.run = function ()
|
||||
callback.mousemoved(motion.x, motion.y)
|
||||
elseif event.type == sdl.KEYDOWN then
|
||||
local key = Keyboard.stringByKeycode[event.key.keysym.sym] or 'unknown'
|
||||
callback.keypressed(key, event.key['repeat'])
|
||||
local scanCode = Keyboard.stringByScancode[event.key.keysym.scancode] or 'unknown'
|
||||
callback.keypressed(key, scanCode, event.key['repeat'])
|
||||
elseif event.type == sdl.KEYUP then
|
||||
local key = Keyboard.stringByKeycode[event.key.keysym.sym] or 'unknown'
|
||||
callback.keyreleased(key, event.key['repeat'])
|
||||
local scanCode = Keyboard.stringByScancode[event.key.keysym.scancode] or 'unknown'
|
||||
callback.keyreleased(key, scanCode, event.key['repeat'])
|
||||
elseif event.type == sdl.TEXTINPUT then
|
||||
callback.textinput(ffi.string(event.text.text))
|
||||
elseif event.type == sdl.MOUSEWHEEL then
|
||||
@@ -350,11 +352,11 @@ function Backend.show (layout)
|
||||
return input:handleMove(layout, x, y)
|
||||
end
|
||||
end)
|
||||
hook(layout, 'keypressed', function (key, isRepeat)
|
||||
return input:handleKeyPress(layout, key, Backend.getMousePosition())
|
||||
hook(layout, 'keypressed', function (key, scanCode, isRepeat)
|
||||
return input:handleKeyPress(layout, key, scanCode, Backend.getMousePosition())
|
||||
end)
|
||||
hook(layout, 'keyreleased', function (key)
|
||||
return input:handleKeyRelease(layout, key, Backend.getMousePosition())
|
||||
hook(layout, 'keyreleased', function (key, scanCode)
|
||||
return input:handleKeyRelease(layout, key, scanCode, Backend.getMousePosition())
|
||||
end)
|
||||
hook(layout, 'textinput', function (text)
|
||||
return input:handleTextInput(layout, text, Backend.getMousePosition())
|
||||
|
||||
@@ -907,7 +907,8 @@ int SDL_GL_SetSwapInterval(int interval);
|
||||
int SDL_GL_GetSwapInterval(void);
|
||||
void SDL_GL_SwapWindow(SDL_Window * window);
|
||||
void SDL_GL_DeleteContext(SDL_GLContext context);
|
||||
typedef enum
|
||||
typedef Sint32 SDL_Scancode;
|
||||
enum
|
||||
{
|
||||
SDL_SCANCODE_UNKNOWN = 0,
|
||||
SDL_SCANCODE_A = 4,
|
||||
@@ -1151,7 +1152,7 @@ typedef enum
|
||||
SDL_SCANCODE_APP1 = 283,
|
||||
SDL_SCANCODE_APP2 = 284,
|
||||
SDL_NUM_SCANCODES = 512
|
||||
} SDL_Scancode;
|
||||
};
|
||||
typedef Sint32 SDL_Keycode;
|
||||
enum
|
||||
{
|
||||
|
||||
@@ -142,13 +142,13 @@ function Backend.show (layout)
|
||||
return input:handleMove(layout, x, y)
|
||||
end
|
||||
end)
|
||||
hook(layout, 'keypressed', function (key, isRepeat)
|
||||
hook(layout, 'keypressed', function (key, sc, isRepeat)
|
||||
if key == ' ' then key = 'space' end
|
||||
return input:handleKeyPress(layout, key, Backend.getMousePosition())
|
||||
return input:handleKeyPress(layout, key, sc, Backend.getMousePosition())
|
||||
end)
|
||||
hook(layout, 'keyreleased', function (key)
|
||||
hook(layout, 'keyreleased', function (key, sc)
|
||||
if key == ' ' then key = 'space' end
|
||||
return input:handleKeyRelease(layout, key, Backend.getMousePosition())
|
||||
return input:handleKeyRelease(layout, key, sc, Backend.getMousePosition())
|
||||
end)
|
||||
hook(layout, 'textinput', function (text)
|
||||
return input:handleTextInput(layout, text, Backend.getMousePosition())
|
||||
|
||||
@@ -20,10 +20,11 @@ function Input:handleDisplay (layout)
|
||||
Event.Display:emit(layout)
|
||||
end
|
||||
|
||||
function Input:handleKeyPress (layout, key, x, y)
|
||||
function Input:handleKeyPress (layout, key, sc, x, y)
|
||||
local widget = layout.focusedWidget or layout.root
|
||||
local result = widget:bubbleEvent('KeyPress', {
|
||||
key = key,
|
||||
scanCode = sc,
|
||||
modifierFlags = Shortcut.getModifierFlags(),
|
||||
x = x, y = y
|
||||
})
|
||||
@@ -31,10 +32,11 @@ function Input:handleKeyPress (layout, key, x, y)
|
||||
if layout.root.modal then return false end
|
||||
end
|
||||
|
||||
function Input:handleKeyRelease (layout, key, x, y)
|
||||
function Input:handleKeyRelease (layout, key, sc, x, y)
|
||||
local widget = layout.focusedWidget or layout.root
|
||||
local result = widget:bubbleEvent('KeyRelease', {
|
||||
key = key,
|
||||
scanCode = sc,
|
||||
modifierFlags = Shortcut.getModifierFlags(),
|
||||
x = x, y = y
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user