Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Keyboard key inputs and key press vs key hold and key release  (Read 4054 times)

0 Members and 1 Guest are viewing this topic.

Brick Nash

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 83
  • Generic Amiga User
Keyboard key inputs and key press vs key hold and key release
« 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.
Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: Keyboard key inputs and key press vs key hold and key release
« Reply #1 on: September 23, 2017, 07:41:24 AM »

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 !)



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!
« Last Edit: September 23, 2017, 07:45:15 AM by Hungry Horace »
Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

Brick Nash

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 83
  • Generic Amiga User
Re: Keyboard key inputs and key press vs key hold and key release
« Reply #2 on: September 24, 2017, 10:27:23 AM »

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.
Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: Keyboard key inputs and key press vs key hold and key release
« Reply #3 on: September 24, 2017, 11:11:14 PM »

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.
Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022