Jump to content




Detecting multiple key presses


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

#1 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 31 August 2014 - 02:21 AM

Hello everyone, I've stumbled upon a problem, it's that I don't know how to detect if multiple keys have been pressed. Like you've might have seen in programs that they use CTRL+S or something. Now how would I do this? can someone give me some code example? do I have to modify os.pullEvent/pullEventRaw or something todo this?
I tried doing this in some weird way using timers, problem was I couldn't hold down a key. ( for example hold down shift, then press left. I had to press shift and then press left )
And if you're wondering if I have to code left to show I can tell you right now that the answer is nope. The code got deleted as it was a test-script and it didn't work.

- Thanks in advance, TheOddByte

#2 natedogith1

  • Members
  • 110 posts

Posted 31 August 2014 - 02:42 AM

There's not really a way to do that in CC (though somewhere on the forums I've seen someone jury-rig it). The best bet is just to see if someone's pressed the two keys within some time of each other.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 August 2014 - 03:23 AM

There's one exception (and only one) that comes to mind - holding down Ctrl while pressing characters generates key events for those characters, but not char events.

This means that if you rig your script to queue a custom event whenever a key event is detected, then see whether a char event can be pulled before that custom event, you can tell whether a given character was held in conjunction with Ctrl or not.

#4 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 31 August 2014 - 05:04 PM

Thanks for the help, I gave it a shot and this was the result.
Spoiler
It's not perfect, but it kinda works :P

Edited by TheOddByte, 31 August 2014 - 05:08 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users