Computer Science Canada Keyboard - if pressed as opposed to if down??? |
Author: | xHoly-Divinity [ Thu Nov 02, 2006 8:50 pm ] |
Post subject: | Keyboard - if pressed as opposed to if down??? |
Is there a command in turing that will just get when a button is pressed? E.g. if i press and hold k, using Input.KeyDown, u would get kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk. Now, what im wondering if i can do is if i press and hold k it only does it once until it is pressed again. Thanks ![]() |
Author: | Windsurfer [ Thu Nov 02, 2006 8:55 pm ] |
Post subject: | |
Use an array of booleans and test to see if the position of the key changed since the last time you checked. Eg. At the start, the whole array would be false. Start Loop. Check all keys. If one key is pressed down AND the corresponding boolean is false, turn the boolean to true and do a command. If a key is not pressed AND the boolean is true, turn the boolean to false. Loop back. |
Author: | ericfourfour [ Thu Nov 02, 2006 9:05 pm ] | ||||
Post subject: | |||||
I think you are trying to ask if you can stop the program from checking if 'k' is pressed until the 'k' is released. In that case you would simply use a boolean variable. First you would check if k is down and if it is you would check if the k was down last cycle (loop) by checking the boolean variable. If it was not down the previous cycle then you would do the 'k' down stuff. If 'k' was not down you would set the boolean to say that in this cycle the 'k' was not down.
Or you could use Input.hasch (I think that is it). If it returns true then there is a key in the input buffer. After that call Input.getchar which returns a string that is the current input. Or you can use Input.getch which returns a string with a length of 1.
|
Author: | xHoly-Divinity [ Thu Nov 02, 2006 9:10 pm ] | ||
Post subject: | |||
Hmmm.... windsurfer that doesn't seem efficient cuzz look
That still doesn't change it, it processes too quickly. Unless that's not exactly what u mean ![]() |
Author: | xHoly-Divinity [ Thu Nov 02, 2006 9:14 pm ] |
Post subject: | |
Ooooo, u actually brought me upon another command. Input.Flush, i think that's what im lookin for ![]() |
Author: | Windsurfer [ Thu Nov 02, 2006 9:19 pm ] | ||
Post subject: | |||
Perhaps you need to re-read my English code... This is what i meant, sort of, in terms of your code, in Turing code:
|
Author: | ericfourfour [ Thu Nov 02, 2006 9:25 pm ] | ||||
Post subject: | |||||
windsurfer??? I don't see anyone named windsurfer in this thread. Anyway, I guess I didn't explain it well enough. I took the time to translate the code to Turing from pseudo.
And I realized the second one wasn't made that well either. It really should look like this:
|
Author: | ericfourfour [ Thu Nov 02, 2006 9:26 pm ] |
Post subject: | |
Haha. I didn't even see that windsurfer was in this thread. |
Author: | Windsurfer [ Thu Nov 02, 2006 9:30 pm ] |
Post subject: | |
And yes, you got the idea in your code. Very nicely done. Except... ah never mind, i never believed in those teaching principles anyways. |
Author: | xHoly-Divinity [ Thu Nov 02, 2006 9:31 pm ] |
Post subject: | |
Nicely done boys, that was quite helpful ![]() |
Author: | bruized [ Fri Nov 03, 2006 3:46 pm ] |
Post subject: | |
Well, I actually had the same question to ask and was going to until I saw this. The thing is I'm not sure I get the gist of what you guys are saying. Well I do but I don't understand how it works like that in the code. I was wondering if you could explain it a little more. |
Author: | ericfourfour [ Fri Nov 03, 2006 3:59 pm ] | ||
Post subject: | |||
My second example is the easiest to implement. I'll add comments beside what is going on.
|