So I'm trying, using direct input, to have some keys work only while a command key is pressed. For instance, while the [+] key is depressed, you can press 1-4, and when [+] is released, the number key you pressed is "engaged". I'm assuming i'd do this easily by maintaining a flag to indicate whether the master key is pressed? is this the easiest way?
Would you not just check if what you're calling the "master" key is pressed, and if so, then also check if [1]-[4] are pressed? I'm not sure I understand this question.
But, the game can't pause while im waiting for the secondary key or a release. So i have to be able to check keys and move on if secondary not pressed
So something like this:

Code:

if (key1) {
  if (key2) {
    do_stuff();
  }
}
You'd want to use a loop, though, since that only detects if they're pressed at the exact same time.


Code:

while (key1) {
    switch (key) {
        case key2:
            do stuff
        case key3:
            do stuff
        //and so on
    }
}
@M.I. Wright, looping freezes the program until i release that key which is not the behavior i want. Ivoah's solution would be preferable. Thanks guys!
M. I. Wright wrote:
You'd want to use a loop, though, since that only detects if they're pressed at the exact same time.


[That's what he wants, also, he said that it can't pause while waiting for the other key, which is exactly what my pseudocode does.

EDIT: Whoops, should have reloaded the page before posting Very Happy
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement