PullEvent, if Char elseif Key, still having issues
#1
Posted 04 June 2014 - 06:54 PM
Regards,
Augustas
#2
Posted 04 June 2014 - 07:13 PM
augustas656 said:
[Edit] And disregard what Abelatox said, that isn't how pullEvent works.
Whitecatblack
Edited by Whitecatblack, 04 June 2014 - 07:14 PM.
#3
Posted 04 June 2014 - 07:15 PM
Whitecatblack, on 04 June 2014 - 07:13 PM, said:
augustas656 said:
[Edit] And disregard what Abelatox said, that isn't how pullEvent works.
Whitecatblack
If I recall correctly, bios.lua file's read() function uses this same concept and somehow still manages to work around by using if "char" and if "key" checks. Wierd
Regards
Augustas
Edited by augustas656, 04 June 2014 - 07:15 PM.
#4
Posted 04 June 2014 - 07:17 PM
Whitecatblack, on 04 June 2014 - 07:13 PM, said:
augustas656 said:
Whitecatblack
Nope. os.pullEvent("char") simply waits until it gets the char event. What actually happens is that pressing a key triggers two events: the key event and the char event. If you were to use os.pullEvent() without arguments you would only get the first event which it receives - that would be the key event in most cases. In order to capture all events you'll want to set up a simple loop:
while true do local eventType, arg1, arg2, arg3 = os.pullEvent() if eventType == "char" then ... elseif eventType == "key" then ... end end
Edited by Bubba, 04 June 2014 - 07:29 PM.
#5
Posted 04 June 2014 - 07:49 PM
Bubba said:
Whitecatblack
#6
Posted 04 June 2014 - 08:39 PM
event = {os.pullEvent()}
if event[1] == "key" and keys.getName( event[2] ) then
--#aha, a character
elseif event[1] == "key" and not keys.getName( event[2] ) then
--#guess its a key event
end
Edited by KingofGamesYami, 04 June 2014 - 08:41 PM.
#7
Posted 04 June 2014 - 08:46 PM
KingofGamesYami, on 04 June 2014 - 08:39 PM, said:
event = {os.pullEvent()}
if event[1] == "key" and keys.getName( event[2] ) then
--#aha, a character
elseif event[1] == "key" and not keys.getName( event[2] ) then
--#guess its a key event
end
Because using 'key' events you cannot tell if the character pressed was capitalized or not.
EDIT: Also, it's shorter:
event = {os.pullEvent()}
if event[1] == "char" then
--#aha, a character
elseif event[1] == "key" then
--#guess its a key event
end
EDIT2: And keys.getName returns names for not printable keys too, or in other words, for all keys, so in your example the first 'if' would never fail.
Edited by MKlegoman357, 04 June 2014 - 08:49 PM.
#8
Posted 04 June 2014 - 08:51 PM
MKlegoman357, on 04 June 2014 - 08:46 PM, said:
KingofGamesYami, on 04 June 2014 - 08:39 PM, said:
event = {os.pullEvent()}
if event[1] == "key" and keys.getName( event[2] ) then
--#aha, a character
elseif event[1] == "key" and not keys.getName( event[2] ) then
--#guess its a key event
end
Because using 'key' events you cannot tell if the character pressed was capitalized or not.
EDIT: Also, it's shorter:
event = {os.pullEvent()}
if event[1] == "char" then
--#aha, a character
elseif event[1] == "key" then
--#guess its a key event
end
EDIT2: And keys.getName returns names for not printable keys too, or in other words, for all keys, so in your example the first 'if' would never fail.
If you read the OP, he already tried that.. Thanks for mentioning that bit about the key to char conversion, I didn't know that.
#9
Posted 05 June 2014 - 01:37 AM
Whitecatblack, on 04 June 2014 - 07:49 PM, said:
local input = ""
while true do
local event = { os.pullEvent() }
if event[1] == "char" then
input = input..event[2]
elseif event[1] == "key" then
if event[2] == keys.enter then
break
elseif event[2] == keys.backspace then
input = input:sub(1, #input - 1)
end
end
end
which given what the above statements do it doesn't even matter what order your have the if ... elseif in.
KingofGamesYami, on 04 June 2014 - 08:39 PM, said:
MKlegoman357, on 04 June 2014 - 08:46 PM, said:
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











