-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
keyboard.fluid
31 lines (22 loc) · 1.01 KB
/
keyboard.fluid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--[[
A basic demonstration of receiving keyboard input from a viewport.
--]]
require 'gui/window'
local win = gui.window({ title='Keyboard Example', insideWidth=400, insideHeight=200,
maxWidth=600, maxHeight=300, minWidth=400, minHeight=200 })
local viewport = win:clientViewport({ aspectRatio = ARF_MEET })
local text = viewport.new('VectorText', {
string='Press a key', face='Noto Sans', fontSize=60, y=50, x=10, fill='rgb(0,0,0)'
})
-- Create a keyboard subscription to the window's main viewport. The applied function will be called every time
-- that the user presses a key when the window has the focus.
viewport.mtSubscribeKeyboard(function(Viewport, Flags, Value, Unicode)
if (Unicode > 0) then
glChars = nz(glChars,'') .. string.char(Unicode)
glChars = glChars:sub(-10)
end
text.string = 'Flags: ' .. string.format('0x%x', Flags) .. '\nCode: ' .. Value .. '\n' .. glChars
viewport.acDraw()
end)
win:show()
processing.sleep()