Another consideration is that you may have to "rate limit" your key presses. Although I'm not sure what kind of latency you're going to get with Nodejs. You're probably getting multiple key press signals from Nodejs by just holding down the key for a fraction of a second. De-bounce could even be a factor here.
So . . . off the top of my head you're going to have to do as Harvey suggests and use a boolean value to toggle the key press state. Then perhaps have a timer OR the value after a set amount of time ( if the key is still physically pressed down ). Depending on if you wish a held down key to send multiple key presses or not. On Sat, Apr 25, 2015 at 6:48 AM, Harvey White <[email protected]> wrote: > On Sat, 25 Apr 2015 00:44:18 -0700 (PDT), you wrote: > > >Hello, > > > >I am currently working on a project that involves using switches (handled > >the same was as a button) and node.js. I am stuck on a part that involves > >making sure the switches are pressed in the correct order. There is an Up > >switch and a Down switch. > > > >The things I need to do: > > > >- The Up switch needs to be the first switched pressed, if the Down switch > >is pressed first I need to print an error (console.log will do) > >- The Up switch cannot be pressed two or more times in a row without > having > >a Down switch press in between, if there are two or more Up switch presses > >in a row it will result in printing an error. > >- The Down switch cannot be pressed two or more times in a row without > >having an Up switch press in between, if there are two or more Down switch > >presses in a row it will result in printing an error. > > > >Any help I can get would be greatly appreciated! I have been stuck on this > >for quite a while and I know it shouldn't be hard its just not coming to > me > >very easily. Everything I have tried so far as been unsuccessful. > > Flow chart this. You will need a routine that sets a boolean variable > when a key has been pressed, or a method of checking when the key has > been pressed. > > A flow chart will give you the program flow, > > Example as a start, using words... > > Initialize all switches to not pressed. > > is switch pressed? if not, loop on this question > > is switch UP switch, if yes, go to next statement, if no print error > // up has to be first > > is switch DOWN switch, if yes, go to DOWN, if not, go to next > statement > > is up switch already pressed? if so, print error. if not, go to next > statement > > .... code here to handle up switch press and then reset up switch > pressed and go back to looking for switch pressed > > DOWN: > is down switch already pressed? if so, print error, if not, go to > next statement > > ..... etc > > > > > Harvey > > > > > > >Thanks. > > -- > For more options, visit http://beagleboard.org/discuss > --- > You received this message because you are subscribed to the Google Groups > "BeagleBoard" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
