If you do something like event,p1,p2,p3 = os.pullEvent(), pressing a will not be char but instead it will be a key event. How can I use the pullevent to get string chars (I don't want to list what character each keyboard numeral relates to.) But I also want to use key, my plan is being able to use char and then make my own read function (that limits how much can be written), you have to click with your mouse to stop writing, and when you press ENTER whilst writing instead of exiting the input you add a "\n" to it which means next line.
How can I do this, do I have to do the numericals and use just key or?
Events, Key & Char, can I have them at the same time?
Started by augustas656, Apr 29 2014 08:24 PM
6 replies to this topic
#1
Posted 29 April 2014 - 08:24 PM
#2
Posted 29 April 2014 - 08:30 PM
Just use if statements
while true do local event,p1,p2,p3 = os.pullEvent() if event == "char" then elseif event == "key" then end endif the keyboard button has a corresponding char, the char event is fired aswell as the key, otherwise only the key is fired.
#3
Posted 29 April 2014 - 08:31 PM
I didn't understand you well, but i think you can make in loop something like this:
Up was first...
I don't know if you can compare char with enter sign. CometWolf's way is better then my D:
All events types you can check here: http://computercraft...ki/Os.pullEvent
while true do
char = os.pullEvent("char")
if char == '/n' then
-- ENTER
else
-- ADD CHAR TO STRING WHAT INCLUDE YOUR TEXT
end
Up was first...
I don't know if you can compare char with enter sign. CometWolf's way is better then my D:
All events types you can check here: http://computercraft...ki/Os.pullEvent
Edited by OczkoSX, 29 April 2014 - 08:34 PM.
#4
Posted 29 April 2014 - 11:45 PM
I actually use something like this in a program I am working on:
Btw, does anyone have the key codes for a mac keyboard? The one on the wiki shows the standard windows keyboard.
event = {os.pullEvent()}
if event[1] == "char" then
s = s..event[2] --#this will change the variable s to s + the key pressed (basically, this acts like read() without showing what they are typing)
term.write(event[2]) --#shows what they typed on screen
elseif event[1] == "key" and (event[2] == 14 or event[2] == 211) then --#checks for delete AND backspace
s = string.sub(s, 1, #s - 1) --#deletes last character.
local x, y = term.getCursorPos() --#these four lines remove the character from the screen
term.setCursorPos(x - 1, y)
term.write(' ')
term.setCursorPos(x - 1, y)
end
Of course, you may want to loop this, I actually have a third statement that ends the loop and returns s when enter is pressed.Btw, does anyone have the key codes for a mac keyboard? The one on the wiki shows the standard windows keyboard.
Edited by KingofGamesYami, 30 April 2014 - 12:24 AM.
#5
Posted 30 April 2014 - 08:07 AM
KingofGamesYami, on 29 April 2014 - 11:45 PM, said:
Btw, does anyone have the key codes for a mac keyboard? The one on the wiki shows the standard windows keyboard.
Keycodes for Mac should be the same as for Windows. If you're using an emulator then it's that emulator's problem.
#6
Posted 30 April 2014 - 09:21 AM
OczkoSX, on 29 April 2014 - 08:31 PM, said:
if char == '/n' then
secondly, pressing enter does not queue a char event, it only queues a key event with the keys.enter key code
local event = { os.pullEvent() }
if event[1] == "char" then
--# it was a letter, number, or punctuation
elseif event[1] == "key" then
--# it was any key on the keyboard except tilde (~)
if event[2] == keys.enter then
--# enter was pressed
end
end
MKlegoman357, on 30 April 2014 - 08:07 AM, said:
They are indeed the same.
Edited by theoriginalbit, 30 April 2014 - 09:22 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











