Skip to content

Commit 4a3c719

Browse files
committed
Fix the keyboard
Completely untested, but this should work...
1 parent f932375 commit 4a3c719

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

miniOS/minios.lua

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,45 @@ function terminal_code()
10401040

10411041
return term
10421042
end
1043+
function keyboard_init()
1044+
local function onKeyDown(_, address, char, code)
1045+
if keyboard.pressedChars[address] then
1046+
keyboard.pressedChars[address][char] = true
1047+
keyboard.pressedCodes[address][code] = true
1048+
end
1049+
end
1050+
1051+
local function onKeyUp(_, address, char, code)
1052+
if keyboard.pressedChars[address] then
1053+
keyboard.pressedChars[address][char] = nil
1054+
keyboard.pressedCodes[address][code] = nil
1055+
end
1056+
end
1057+
1058+
local function onComponentAdded(_, address, componentType)
1059+
if componentType == "keyboard" then
1060+
keyboard.pressedChars[address] = {}
1061+
keyboard.pressedCodes[address] = {}
1062+
end
1063+
end
1064+
1065+
local function onComponentRemoved(_, address, componentType)
1066+
if componentType == "keyboard" then
1067+
keyboard.pressedChars[address] = nil
1068+
keyboard.pressedCodes[address] = nil
1069+
end
1070+
end
1071+
1072+
for address in component.list("keyboard", true) do
1073+
onComponentAdded("component_added", address, "keyboard")
1074+
end
1075+
1076+
event.listen("key_down", onKeyDown)
1077+
event.listen("key_up", onKeyUp)
1078+
event.listen("component_added", onComponentAdded)
1079+
event.listen("component_removed", onComponentRemoved)
1080+
end
1081+
10431082
local function printProcess(...)
10441083
local args = table.pack(...)
10451084
local argstr = ""
@@ -1160,9 +1199,10 @@ text = text_code()
11601199
filesystem = fs_code()
11611200
fs = filesystem
11621201
keyboard = dofile("keyboard.lua")
1202+
keyboard_init()
11631203
term = terminal_code()
11641204

1165-
-- set up other libraries...
1205+
-- set up other functions...
11661206
os.sleep = function(timeout)
11671207
checkArg(1, timeout, "number", "nil")
11681208
local deadline = computer.uptime() + (timeout or 0)

0 commit comments

Comments
 (0)