Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function onKeyDown(char, code)
- if code == keyboard.keys.back and not readonly then
- if left() then
- delete()
- end
- elseif code == keyboard.keys.delete and not readonly then
- delete()
- elseif code == keyboard.keys.left then
- left()
- elseif code == keyboard.keys.right then
- right()
- elseif code == keyboard.keys.home then
- home()
- elseif code == keyboard.keys["end"] then
- ende()
- elseif code == keyboard.keys.up then
- up()
- elseif code == keyboard.keys.down then
- down()
- elseif code == keyboard.keys.pageUp then
- local w, h = getSize()
- up(h - 1)
- elseif code == keyboard.keys.pageDown then
- local w, h = getSize()
- down(h - 1)
- elseif code == keyboard.keys.enter and not readonly then
- enter()
- elseif readonly and code == keyboard.keys.q then
- running = false
- elseif not keyboard.isControl(char) and not readonly then
- insert(unicode.char(char))
- end
- end
- while running do
- local event, address, arg1, arg2, arg3 = event.pull() -- arg1 equates to char, arg2 is code in the onKeyDown() function
- if type(address) == "string" and component.isPrimary(address) then
- local blink = true
- if event == "key_down" then
- onKeyDown(arg1, arg2)
- else
- blink = false
- end
- if blink then
- term.setCursorBlink(true)
- term.setCursorBlink(true) -- force toggle to caret
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement