Using the space bar for input
Author |
Message |
Daetyrnis
|
Posted: Tue Apr 03, 2007 5:38 pm Post subject: Using the space bar for input |
|
|
Well, I'm working on a game and I've been using Input.KeyDown to detect user input. It detects the arrow keys fine (as it should), but then when looking at the Keyboard Module in the documentation, I discovered something. The space bar is an ORD, not a KEY! As far as I know, that means that SPACE is a value (as in, an integer), as opposed to the other buttons (such as arrows) being actual characters.
So, long story short, how can I use the space bar for input, preferably keeping my layout with Input.KeyDown. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Expirant
|
Posted: Tue Apr 03, 2007 6:39 pm Post subject: Re: Using the space bar for input |
|
|
I think this is what you meant. I just did a quick experiment to find space bar's ordinal value, then used the chr function (look it up) to do the same thing all those KEY_LEFT_ARROW etc. things do.
code: |
var userInput : array char of boolean
loop
Input.KeyDown (userInput)
if userInput (chr (32) /* Space bar's ordinal value on PCs is 32 */) then
put "This way works."
exit
end if
end loop
|
Hope that helps,
Expirant |
|
|
|
|
|
Daetyrnis
|
Posted: Tue Apr 03, 2007 7:38 pm Post subject: RE:Using the space bar for input |
|
|
That worked wonderfully, thanks. ^_^
Ya' know, I was thinking that is was going to be something along those lines, using chr or ord. I just figured that it would be faster to ask here than look it up myself.
._.' |
|
|
|
|
|
Geostigma
|
Posted: Tue Apr 03, 2007 8:16 pm Post subject: RE:Using the space bar for input |
|
|
Or you could use like a normal person. |
|
|
|
|
|
ericfourfour
|
Posted: Tue Apr 03, 2007 11:18 pm Post subject: RE:Using the space bar for input |
|
|
Geostigma is correct. There is no point in going out of your way to remember some number of a character when you can just type the character. I am pretty sure Turing did not come with a constant called KEY_SPACE_BAR because you can use ' '. |
|
|
|
|
|
Expirant
|
Posted: Wed Apr 04, 2007 10:25 am Post subject: Re: Using the space bar for input |
|
|
I suppose using (' ') works as well, my bad.
Good call, Geostigma. |
|
|
|
|
|
Daetyrnis
|
Posted: Wed Apr 04, 2007 3:32 pm Post subject: RE:Using the space bar for input |
|
|
Ah, that seems to work as well. ._.'
Thanks for your input Expirant, but Geostigma did provide a better answer. >_> |
|
|
|
|
|
|
|