Jump to content




raw key events laying over?


  • You cannot reply to this topic
2 replies to this topic

#1 murky white

  • Members
  • 7 posts

Posted 15 June 2013 - 01:46 PM

when i use os.pullEvent("key") in a program, it seems like the last key grabbed will also be entered into the shell when the program exits.

so if i run a program like this:
local ev, k = os.pullEvent("key")
print(k)

it will also type whatever key i press into the shell if it is a visible character. it doesn't seem to happen with arrow keys or return. is there any way to prevent this?

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 15 June 2013 - 01:55 PM

Well, the problem is that there's a "char" event after the "key" event for printable keys. So, you are pulling the "key" event, but the corresponding "char" event is left in the queue, and the shell pulls it and writes it to the console. It shouldn't afect programs, since you will probably pull the char event too. So there's no need to fix this "problem".

#3 GopherAtl

  • Members
  • 888 posts

Posted 15 June 2013 - 02:09 PM

you can prevent those dangling chars from getting typed on program exit by adding this right before you exit the program:

os.queueEvent("dummy")
os.pullEvent()

The dummy event is added just to make sure there's something in the queue, otherwise it might end up waiting for a real event. If there's a char event waiting, the pullEvent will grab it; if there was not, it'll get the dummy.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users