Jump to content
erichenneke

Using keyboard for controls instead of joystick

Recommended Posts

I want to use the keyboard arrow keys to control left and right in a basic game, as an alternative to a joystick option.

 

I thought this would be simple, but realized I guess I've never done this before on the Atari because it's actually not working very well!

 

What I want is just a momentary on switch. If the left arrow is pressed do something ( but only while it is pressed ), if the right arrow is pressed do something else ( but only while it is pressed ). If neither are pressed, do nothing.

 

If I use a PEEK(764) the problem is that then it stays the same value until another key is pressed. So if the left arrow is pressed once and then released, it continues to read as if it is pressed until another key is pressed. That is not what I need. I tried POKEing 0 or 255 into 764 in between each PEEK(764) but that results in a very jerky and inconsistent reading. Like you have to tap the arrow key over and over. I want to be able to press the arrow key and hold it down as long as the user wants....just like a joystick would work.

 

I also tried OPENing K: and GET, but that is no good because it pauses and waits for input.

 

In Turbo Basic XL i tried using the INKEY$ function, but it essentially seems to behave similar to PEEK(764) from this standpoint.

 

Surely there is a way to do this because I know of multiple games that allow a keyboard control option with similar behavior to a joystick.

 

What's the trick? And can it be done from basic ( or TBXL) ?

 

Thanks!!!

-Eric

 

 

Share this post


Link to post
Share on other sites

First PEEK SKTAT to see if bit 2 is 0 which indicates that a key is being pressed. Then PEEK KBCODE to get the raw POKEY keyboard code. See Compute's Third Book of Atari for a table of keycodes.

 

0 KBCODE=$D209:SKSTAT=$D20F
10 IF NOT PEEK(SKSTAT)&4:CODE=PEEK(KBCODE):XD=(CODE=7)-(CODE=6):ELSE:XD=0:ENDIF
20 PRINT XD:GOTO 10
  • Like 2

Share this post


Link to post
Share on other sites

Keyboard isn't a very good control method on the Atari because the time-saving Pokey key scan in fact limits detecting multiple key presses.

That means multiplayer simultaneous kb games are near impossible and single player ones are cumbersome.

 

Exceptions are - the console keys are always independant and not affected by each other or normal keys.

- Shift key can be detected independantly but there's no differentiation between each of them.

- Control key can only be "assumed" by it's bit in the keyboard code. You can release Ctrl but keep holding the normal key and it'll still return the code indicating Ctrl is being pressed. Ctrl key on it's own or with console key returns nothing.

- Shift + Ctrl + third key won't work for keys that are on the same scan row as them, ie - Help B V C X Z J K L ; + *

 

So, keyboard is sort of a poor arcade input method. For something like a Galaxian type game it would be OK since the directions aren't needed at the same time and you could use Shift as the fire button.

Edited by Rybags
  • Like 1

Share this post


Link to post
Share on other sites

For Breakout/Arkanoid type games keyboard are also fine because you move only to left and right so is each time always a single press.

Back in the 80s Arkanoid and untill now on A8 and others I only use keyboard because joystick always seemed impossible to me. In Arkanoid case is that you also, like Rybags said, can use with no constraints, the SHIFT key for fire :).

Others that is the same for me are Tetris type of games.

Edited by José Pereira
  • Like 1

Share this post


Link to post
Share on other sites

Those types suffer too but it's equivalent to joystick. It's fixed speed movement vs variable for paddle. About all that can be done is assign fire button or Shift which can be held to give slower or faster velocity.

  • Like 1

Share this post


Link to post
Share on other sites

Those types suffer too but it's equivalent to joystick. It's fixed speed movement vs variable for paddle. About all that can be done is assign fire button or Shift which can be held to give slower or faster velocity.

I never had a paddle :( and ever remember to saw in any of stores in here at that time. Edited by José Pereira

Share this post


Link to post
Share on other sites

First PEEK SKTAT to see if bit 2 is 0 which indicates that a key is being pressed. Then PEEK KBCODE to get the raw POKEY keyboard code. See Compute's Third Book of Atari for a table of keycodes.

 

0 KBCODE=$D209:SKSTAT=$D20F
10 IF NOT PEEK(SKSTAT)&4:CODE=PEEK(KBCODE):XD=(CODE=7)-(CODE=6):ELSE:XD=0:ENDIF
20 PRINT XD:GOTO 10

Thank you! Checking SKSTAT first was the piece of the puzzle i was missing !

 

 

Share this post


Link to post
Share on other sites

The game i want to use this on is only a left/right situation ( like space invaders, etc. ) so this is PERFECT.

 

Thanks all !

-Eric

  • Like 1

Share this post


Link to post
Share on other sites

The game i want to use this on is only a left/right situation ( like space invaders, etc. ) so this is PERFECT.

 

Thanks all !

-Eric

I would suggest predefined left/right: Z<->X and . <->/ keys that fit to left and right hand users that is near SHIFT if you need it for fire or jump (or you can always let the user to choose but SHIFT need always to be). Edited by José Pereira

Share this post


Link to post
Share on other sites

I would suggest predefined left/right: Z<->X and .<->/ keys that fit to left and right hand users that is near SHIFT if you need it for fire or jump (or you can always let the user to choose but SHIFT need always to be).

And like Rybags said, the A8 doesn't distinguish between the two SHIFT keys so if having those left/right keys that will fit to all because you can:

-> If you're left hand and want to only use that hand one finger gets to left SHIFT;

-> The same for right hand user get right SHIFT;

-> Use Z<->X and the right hand one finger to press SHIFT (the one I prefer:));

-> Use .<->/ and the left hand one finger to press SHIFT;

:thumbsup:

Edited by José Pereira

Share this post


Link to post
Share on other sites

Other type games that work with keyboard are 2d Pac-Man type of games because he's always moving and you'll need to press a single key each time to change direction. You can have the up/down left/right 4keys predefined or give the user the possibility to choose them.

 

P.s.- Strange or perhaps not that although I'm right hand and on joystick always prefered and had the ones with the stick on the right to use with the right hand and button on the left to use it with left hand one finger but keyboard that on Arkanoyd I used two fingers of the left hand on the Z<->X keys and a finger of the right hand to press SHIFT for fire.

Edited by José Pereira

Share this post


Link to post
Share on other sites

I'd suggest allow redefining input keys.

 

Some people are just used to WASD for FPS games so might want AD for L/R. Also some prefer adjacent keys and others like them apart a bit more.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...