Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Send keyboard inputs as rednet signals to a set ID
- peripheral.find("modem", rednet.open);
- local id = 0;
- local event, key;
- function setID()
- print("Setting new ID\nPress Right Ctrl to set");
- print("Last ID: "..tostring(id));
- key = 0;
- id = 0;
- while true do
- event, key = os.pullEvent("key");
- if key == 345 then
- break
- elseif key > 47 and key < 58 then
- id = id * 10 + (key - 48);
- print(tostring(id));
- end
- end
- print("ID set");
- end
- print("Change ID with Right Ctrl\nMove with wasd\nOther controls are R, U, I, O, P, J, K, 8, and 9.\nPress them at any time to see what they do.");
- setID();
- local directionKeys = {87, 32, 340, 83, 65, 68};
- local function waitForPressed()
- event, key = os.pullEvent("key");
- end
- local function waitForReleased()
- repeat
- event, key = os.pullEvent("key_up");
- local direction = false;
- for index, value in ipairs(directionKeys) do
- if value == key then
- direction = true;
- end
- end
- until direction == false;
- key = 0;
- end
- local function tick()
- while true do
- os.sleep(5)
- print("Tick");
- end
- end
- -- parallel.waitForAny(waitForPressed, waitForReleased);
- while true do
- parallel.waitForAny(waitForPressed, waitForReleased);
- if key == 345 then
- setID();
- else
- rednet.send(id, key);
- local id, message = rednet.receive();
- if key == 49 then
- print("Selected "..message);
- elseif message ~= "" then
- print(message);
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement