Computer Science Canada Input.KeyDown problem |
Author: | Paul [ Sun Mar 14, 2004 10:39 am ] | ||||
Post subject: | Input.KeyDown problem | ||||
Im trying to get the program to detect if a predetermined letter has been pressed. and the predetermined letter is going to be a variable. I don't have alot of experience with this so I dunno if this is the way to do it. And I got an error. in short this is it:
In here, Im trying to check if the user has typed the frist letter of horse, which is h, and if h has been pressed, it exits the loop. Since this is during another part of the program, Im not using getch. but I recieve an error on the line:
of array subscript is out of range I looked at the reference, and I thought if chars('t') works why shouldn't letter, which is a string with the length of one work? Im baffeled, since if I use chars('h') it works, and if I use chars(letter) it won't, even though letter = h. Im putting a halt on what Im doing currently cause of this |
Author: | recneps [ Sun Mar 14, 2004 10:45 am ] | ||||
Post subject: | |||||
KeyDown uses "char"s they're declared like this
from there, just go to turing reference to find the codes. Eg.
|
Author: | Paul [ Sun Mar 14, 2004 10:49 am ] | ||
Post subject: | |||
oh, so I'd have something like this:
it works, so, the chars (thingy) thingy has to be a char? |
Author: | recneps [ Sun Mar 14, 2004 12:24 pm ] | ||
Post subject: | |||
noooooo look in turing reference, theres a thing on front page that says "keycode values returned by...." clikc that and it give you the number for each key.... ex.
Understand it a tad more? |
Author: | Paul [ Sun Mar 14, 2004 12:28 pm ] |
Post subject: | |
Don't have to understand it, it works now |
Author: | Cervantes [ Sun Mar 14, 2004 12:29 pm ] | ||
Post subject: | |||
hey paul. You don't need the part with letters and CL in there any more. it works like this:
|
Author: | Paul [ Sun Mar 14, 2004 12:34 pm ] |
Post subject: | |
I know, but CL changes, just look at my finished program in the source code section, its not that well coded but meh. |
Author: | recneps [ Sun Mar 14, 2004 12:38 pm ] |
Post subject: | |
Well at least you got it working Thats what matters. |