Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local radio = self.CreateLink("radio")
- local keyboard = self.CreateLink("keyboard")
- local console = self.CreateLink("console")
- local y = 0
- local x = 0
- local Caps = false
- local NumberCaps = '!"£$%^&*()'
- local SpecialKeys = {
- [61] = "\\",
- [62] = "-",
- [63] = "=",
- [65] = " ",
- [58] = ",",
- [59] = ".",
- [60] = "/"
- }
- local SpecialKeys_Caps = {
- [61] = "|",
- [62] = "_",
- [63] = "+",
- [58] = "<",
- [59] = ">",
- [60] = "?"
- }
- function GetCharFromKey(key)
- if key >= 1 and key <= 10 then
- if Caps then return NumberCaps[key - 1] end
- return string.char(key + (48 - 1))
- end
- if key >= 37 and key <= 46 then
- return string.char(key + (48 - 37))
- end
- if key >= 11 and key <= 36 then
- if Caps then
- return string.upper(string.char(key + (97 - 11)))
- end
- return string.char(key + (97 - 11))
- end
- if Caps then
- return SpecialKeys_Caps[key] or SpecialKeys[key]
- end
- return SpecialKeys[key]
- end
- local first = true
- local current = ""
- local towrite = {}
- function ReadKeyboard()
- while true do
- local event = keyboard.NextEvent()
- if not event then break end
- if event.Key == 79 then -- Shift
- Caps = event.Down
- continue
- elseif event.Key == 51 or event.Key == 64 then -- ENTER
- if string.len(current) == 0 then continue end
- for i = 1, string.len(current) do
- table.insert(towrite, string.byte(current[i]))
- end
- table.insert(towrite, 0)
- y = y + 1
- if y == 60 then y = 0 console.Clear(Color(0, 0, 0, 255)) end
- console.Draw(":" .. current, 0, y)
- console.Draw(string.rep(" ", 61), 0, 61, Color(0, 0, 0), Color(0, 0, 0, 255)) -- clear the last line
- current = ""
- continue
- end
- if not event.Down then continue end
- local char = GetCharFromKey(event.Key)
- if not char then continue end
- current = current .. char
- console.Draw(char, string.len(current), 61)
- end
- end
- function Think()
- if not radio.Connected then return 1 end
- if not keyboard.Connected then return 1 end
- if not console.Connected then return 1 end
- if first then
- first = false
- console.Clear(Color(0, 0, 0, 255))
- end
- if keyboard.HasTyper() then
- ReadKeyboard()
- end
- if radio.HasData() then
- local str = ""
- while radio.HasData() do
- local b, amp = radio.ReadByte()
- if b == 0 then
- y = y + 1
- if y == 60 then y = 0 console.Clear(Color(0, 0, 0, 255)) end
- console.Draw(str, x, y)
- x = 0
- str = ""
- else
- str = str .. string.char(b)
- end
- end
- if str != "" then
- console.Draw(str, x, y + 1)
- x = x + string.len(str)
- end
- else
- if (#towrite) >= 1 then
- local b = towrite[1]
- table.remove(towrite, 1)
- radio.WriteByte(b)
- end
- end
- return 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement