Jump to content




converting keycode to char


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

#1 Exerro

  • Members
  • 801 posts

Posted 20 January 2013 - 01:46 AM

Im making a program that needs to listen to multiple events so os.pullEvent("char") wont work...and i need to be able to turn keycodes into chars because for some reason the "char" event is never fired when i press a key
I have also tried string.char(p1) but i guess the mc keycodes are different to lua ones because it never returns the right value
Please help!

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 01:51 AM

View Postawsumben13, on 20 January 2013 - 01:46 AM, said:

Im making a program that needs to listen to multiple events so os.pullEvent("char") wont work...and i need to be able to turn keycodes into chars because for some reason the "char" event is never fired when i press a key
I have also tried string.char(p1) but i guess the mc keycodes are different to lua ones because it never returns the right value
Please help!
Yes the ASCII char set has different numbers to the keyboard key bindings of LWJGL... You should be able to use keys.getName( keycode ) ... However this will also return things like "CTRL" for other keys just not char... There must be some reason why the char event isn't working, can you show us the relevant code please?

#3 Exerro

  • Members
  • 801 posts

Posted 20 January 2013 - 02:06 AM

its about 1000 lines spread across 5 programs...so i cant really show code...but i use a program that sleeps between os.pullEvent() so if char and key is fired next to eachother it might not pick up the char
edit: thanks for the help...keys.getName(p1) works :D

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 02:14 AM

can't even show the main loop where you are trying to read the char/key?

ahhh your using sleep... thats eats events... meaning your program will sometimes miss some, you should avoid sleeps when using an event loop and instead use timers ( which is how sleep works anyways )...

#5 Exerro

  • Members
  • 801 posts

Posted 20 January 2013 - 02:18 AM

oh yeah re-read my code it starts a timer and does os.pullEvent() but if a key is repeatedly pressed it would bypass this so it sleeps if it wasnt the timer that triggered the event...
and the input code:
Spoiler






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users