Ultimate Amiga
Network Boards => AMOS Programming Environment => AMOS Factory => AMOS BASIC => Topic started by: Brick Nash on September 22, 2017, 06:40:16 AM
-
Hi all,
I'm trying to figure out how to use keys on the keyboard for inputs. Now it may be my dyslexia kicking in, but when I read the "using the keyboard" section in the manual I find it incredibly confusing.
The one button joystick is too limited for what I'm trying to do so I want to use the keys A,S,and D as separate fire buttons which do different things, but as I say I'm finding the descriptions a bit hard to digest and I was wondering if some could put it in simpler terms for me, or even just a simple example. How would it work with an IF statement for example -
If *code for pushing key A*
do stuff
End If
Also, I'd like to know how to differentiate between a key (or joystick movement) being pressed or tapped as opposed to being held down. Also, to know how to code when a key has been released or un-pressed would be great as well.
It's a bit of a wordy request, but I'm terrible with manuals as they seem to say one thing and then give an example which is totally different to the description (or at least that's how my brain perceives it).
Thanks, I appreciate any help I can get.
-
So you just want to know how to read a key press in?
I hope I can help :)
I think there are other ways, but I like....
If key state($40) = true
Print " you pressed space"
End if
The value for $40 is the hex code (you can convert to decimal if you want) for the space bar.
The scancode numbers for each keyprrss you can find on this: (stolen from whdload.de !)
(http://www.ultimateamiga.co.uk/HostedProjects/GamesCorner/TheCryptOfBloodwych/Images/Editor/KeyRaw.gif)
You could also use = false to check for key release... perhaps you need to loop something whilst holding , or you include both if = true and an Else statement
Hope this is what you need!
-
So you just want to know how to read a key press in?
I hope I can help :)
You most certainly have. That is exactly what I was looking for so thank you very much.
Would it be worth my while setting up some variables for ease of use? Such as Q=$10 and just do that for the whole alphabet or even the whole keyboard? I'm very conscious of memory since beginning Amiga programming so I don't want to take up space for what is essentially a luxury.
-
I would save the variables and use the actual scancode value in the IF statement , but maybe write in your comments/REM statement adjacent which key you are checking.
You will probably be surprised how quickly you start knowing the patterns of which number = which key.