123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|689|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> reading more than one keypress at a time...

Wed, 23 Apr 2008, 20:33
Orion Pax
So how would I go about reading more than one keypress at a time...eg the 1 key and Shift key at same time....
Wed, 23 Apr 2008, 23:07
codingmonkey
Its from my coding experience that
its advisable to set up a keyed poll timer of some sort.

Normally and usually, the KeyHit command is very, very fast. A few possible ways are these:

(1)set up a timer for the 1 key being pressed.
In this case. Lets say after a few milliseconds. Oh around 20 milliseconds or so you test if a shift key is being pressed with the Keyhit command again. And then set up another timer for keyboard bounce.

(2) DO the same like in above, but one bigger timer loop. And within the timer loop test in this case for the shift key. Then perhaps add another but smaller timer loop.
And perhaps with the Flushkey command too.

I hope this helps.


Wed, 23 Apr 2008, 23:38
codingmonkey
Here is a rough draft program.
I used 1 and the Control keys.
And also the 2 key to clear the screen.
Adjust the delay times yourself.
Or set up your own timers.



Remember about keyboard bounce.
Its very fast. In the machine cycles too.
Thu, 24 Apr 2008, 00:13
HoboBen
I would simply do "If KeyDown(KEY_1) and KeyDown(KEY_SHIFT) then"

Is there any problem with just doing that?

If you're doing multiple keyhit/keydown checks, it can be better to do the check first thing, e.g. something like this:



-=-=-
blog | work | code | more code
Thu, 24 Apr 2008, 01:18
codingmonkey

Perhaps.
But remember these keyHit commands are fast.
Very Fast. And you have to take in count of keyboard bounce.
I don't know anyone personally who can strike 2 keys really fast.
Maybe an octopus.

But there is an nested if Keyhit comparsion in there too.

Thu, 24 Apr 2008, 03:41
Yo! Wazzup?
I'm with Hobo... lol
Ive actually made a program that checks for the mouse buttons and space at the same time, and it uses that method.

-=-=-
Hi everyone! I'm new to Blitz and only 10 years old so all things coding is gush to me
Thu, 24 Apr 2008, 03:49
Jayenkai
Me too, There's nothing wrong with Hobo's method, except for the occasional keyboard hardware glitches..

if (keydown(42) or keydown(54)) and keydown(20) then debuglog "You hit shift and T!!! Wowie Yowie!!"

Issues arise when users are trying to hit certain combinations, but I can't really see that happening in your game.

(issues like, you can't hit Left, Up and Space all together.. That's a git in most games! But since yours uses mouse control, you're not having to, say, turn and fire simultaneously with the keyboard.)


... Also : If you need a quick reference to scancodes, there's a little link, at the bottom of the left sidebar.

-=-=-
''Load, Next List!''
Thu, 24 Apr 2008, 04:28
Yo! Wazzup?
Or the HTML interactive scancodes thing in the B3D demo, just copy the HTML file over to your version of Blitz and edit the HTML of the command ref.

-=-=-
Hi everyone! I'm new to Blitz and only 10 years old so all things coding is gush to me
Thu, 24 Apr 2008, 05:31
Orion Pax
I tried keydown...just not twice...i did a keyhit/keydown combo...

keydown looks for keys being HELD down...so you could look for the entire keyboard being held down at one time and it will catch it. There isnt a timing issue with keydown. I just didnt think about using it twice.

DUH....

I remember with my old atari if you held down a modifier key (shift control, didnt have alt) it produced a different code. almost like the shift key code plus the regular key code. something to that effect.

EDIT -- So I did a keydown/keydown combo and it worked!
Thu, 24 Apr 2008, 06:50
JL235
As a slight off-topic remark, I'd advise you try to abstract checking for user input and detecting the actual user input apart. So for example checking if the user is going forward is seperate to checking if the user is pressing the W, up arrow or numpad 8 keys.

This should help to make changing how the user gives input easier (say to take input from a joystick, mouse or even via a network instead) since you only have to change how you detect user input and not how the game uses that input.
Thu, 24 Apr 2008, 11:10
codingmonkey
Implemented Hobos' method but it didn't work.
The method Orion advised did work.
But again, remember keyboard bounce.
That with KeyDown, keys must be pressed fully down too.


But granted, there is more than one way to go about for the same purpose.