Edit2: forgot to say, this program should work as a keyboard now
Edited by KingofGamesYami, 19 April 2014 - 01:20 AM.
Posted 18 April 2014 - 03:41 PM
Edited by KingofGamesYami, 19 April 2014 - 01:20 AM.
Posted 19 April 2014 - 01:12 AM
Posted 19 April 2014 - 01:16 AM
Bomb Bloke, on 19 April 2014 - 01:12 AM, said:
Edited by KingofGamesYami, 19 April 2014 - 01:28 AM.
Posted 19 April 2014 - 01:18 AM
Posted 19 April 2014 - 01:46 AM
local mon = peripheral.wrap("right")
local dmon = peripheral.wrap("monitor_4")
--# we can use an empty string for input, no need to use a table to then put it in the input
--# we can also use booleans, instead of a string 'True' and 'False'
local input, shiftPressed = "", false
--# a table containing the possible keyboard inputs
local keyboard = {
--# the table key is the shift state, yes we can use booleans as keys in tables!
[true] = { "!@#$%^&*() |delete|"," QWERTYUIOP"," ASDFGHJKL |enter|"," ZXCVBNM |shift|"},
[false] = {"1234567890 |delete|"," qwertyuiop"," asdfghjkl |enter|"," zxcvbnm |shift|"}
}
dmon.setTextScale(3)
mon.setTextScale(4)
mon.setBackgroundColor(colors.blue)
mon.clear()
while true do
--# render, we don't need to clear as the lines are the same length so will override previous
for i = 1, 4 do
mon.setCursorPos(1, i)
--# lookup the keyboard with the shift state and line
mon.write(keyboard[shiftPressed][i])
end
--# wait for input
local event, side, x, y = os.pullEvent("monitor_touch")
--# all keyboard characters end before any button, meaning we can use the following logic
if x <= 11 and y <= 4 then
--# look up the keyboard character based on shift state, the y position, and the x position
local char = string.sub(keyboard[shiftPressed][y], x, x)
--# if there was a character at that possition
if char ~= ' ' then
--# append the character to the input
input = input..char
end
--# Delete Button
elseif y == 1 and x >= 13 and x <= 20 then
--# remove the last char
input = input:sub(1, #input-1)
--# the click was at the position of enter or shift
elseif x >= 14 and x <= 20 then
--# enter button
if y == 3 then
if input == "Pa55w0rd" then
rednet.open("left")
rednet.broadcast("Success!")
rednet.close("left")
end
input = "" --# reset the input
--# shift button
elseif y == 4 then
shiftPressed = not shiftPressed --# invert the shiftPressed 'not true == false', 'not false == true'
end
end
dmon.clear()
dmon.setCursorPos(1, 2)
dmon.write(input)
--# removed the sleep, it means you can miss monitor touches
end
Edited by theoriginalbit, 19 April 2014 - 01:47 AM.
Posted 19 April 2014 - 03:31 AM
theoriginalbit, on 19 April 2014 - 01:46 AM, said:
local mon = peripheral.wrap("right")
local dmon = peripheral.wrap("monitor_4")
--# we can use an empty string for input, no need to use a table to then put it in the input
--# we can also use booleans, instead of a string 'True' and 'False'
local input, shiftPressed = "", false
--# a table containing the possible keyboard inputs
local keyboard = {
--# the table key is the shift state, yes we can use booleans as keys in tables!
[true] = { "!@#$%^&*() |delete|"," QWERTYUIOP"," ASDFGHJKL |enter|"," ZXCVBNM |shift|"},
[false] = {"1234567890 |delete|"," qwertyuiop"," asdfghjkl |enter|"," zxcvbnm |shift|"}
}
dmon.setTextScale(3)
mon.setTextScale(4)
mon.setBackgroundColor(colors.blue)
mon.clear()
while true do
--# render, we don't need to clear as the lines are the same length so will override previous
for i = 1, 4 do
mon.setCursorPos(1, i)
--# lookup the keyboard with the shift state and line
mon.write(keyboard[shiftPressed][i])
end
--# wait for input
local event, side, x, y = os.pullEvent("monitor_touch")
--# all keyboard characters end before any button, meaning we can use the following logic
if x <= 11 and y <= 4 then
--# look up the keyboard character based on shift state, the y position, and the x position
local char = string.sub(keyboard[shiftPressed][y], x, x)
--# if there was a character at that possition
if char ~= ' ' then
--# append the character to the input
input = input..char
end
--# Delete Button
elseif y == 1 and x >= 13 and x <= 20 then
--# remove the last char
input = input:sub(1, #input-1)
--# the click was at the position of enter or shift
elseif x >= 14 and x <= 20 then
--# enter button
if y == 3 then
if input == "Pa55w0rd" then
rednet.open("left")
rednet.broadcast("Success!")
rednet.close("left")
end
input = "" --# reset the input
--# shift button
elseif y == 4 then
shiftPressed = not shiftPressed --# invert the shiftPressed 'not true == false', 'not false == true'
end
end
dmon.clear()
dmon.setCursorPos(1, 2)
dmon.write(input)
--# removed the sleep, it means you can miss monitor touches
end
Posted 19 April 2014 - 03:33 AM
KingofGamesYami, on 19 April 2014 - 03:31 AM, said:
Edited by theoriginalbit, 19 April 2014 - 03:33 AM.
Posted 19 April 2014 - 03:45 AM
theoriginalbit, on 19 April 2014 - 03:33 AM, said:
Edited by KingofGamesYami, 19 April 2014 - 03:57 AM.
Posted 19 April 2014 - 06:28 AM
KingofGamesYami, on 19 April 2014 - 03:45 AM, said:
Edited by theoriginalbit, 19 April 2014 - 06:28 AM.
Posted 19 April 2014 - 10:27 PM
theoriginalbit, on 19 April 2014 - 06:28 AM, said:
KingofGamesYami, on 19 April 2014 - 03:45 AM, said:
--#this is not exact, writing from memory
function render()
mon.setCursorPos(1, 1)
mon.write("QWERTYUIOP")
mon.setCursorPos(2, 2)
mon.write("ASDFGHJKL |SHIFT|")
mon.setCursorPos(3, 3)
mon.write("ZXCVBNM |ENTER|")
end
function shift()
if shift == true then
shift = false
else
shift = true
end
end
random_var, ranodom_var2, x, y = os.pullEvent("monitor_touch")
--#not gonna write out all the if/then statements for the touches, I had actually specified each d*mn letter -_-/>/>
if y == 1 and x == 1 then
touched[#touched+1] = "A"
elseif --#...
elseif (shift pressed) then --#not going to figure the location out atm
shift()
end
if shift = true then
term.write(touched[#touched])
else
term.write(string.lower(touched[#touched]))
end
shell.run("Key") --loop program by calling itself
Edited by KingofGamesYami, 19 April 2014 - 10:28 PM.
0 members, 1 guests, 0 anonymous users