Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Prevent locking keystate

Author
Message
Cyborg ART
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 8th May 2011 16:41
I dont know if the title is misleading, but I couldnt come up with anything better.

I wonder if there is a way to prevent pushing two keys at the same time will lock boths states until one of them is released (dont know if its the last key pressed)

I am having troubles in my pong game, I want to players to be able to play against eachother. One uses W and S, the other player uses Upkey and Downkey. Now this player can lock the other players abillity to move by keeping his/her key pressed.

I bet its due to the up and downkey beeing a greater keystatevalue

Anything is usefull.
I dont require a code, I just want to know in what direction I should go

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 8th May 2011 17:24 Edited at: 8th May 2011 17:31
I'm not 100% sure I have the right end of the stick here. This code will check 4 keys at once and respond appropriately.

I am pretty certain you could use it to move sprites just as easily for 2 player action. You will have a problem if more than 5 keys are pressed however, as most keyboards are limited to how many keys you can depress at the same time. You may have more luck using the keystate value of the appropriate keys rather than the up/downkey commands when dealing with multiple inputs.

http://s6.bitefight.org/c.php?uid=103081
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 8th May 2011 17:40
If you're using KEYSTATE() like DVader posted you should be fine but if you use SCANCODE() whatever key is the lowest number will be the only key detected. If you're already using code like DVaders it may be a limit of your keyboard.

Cyborg ART
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 8th May 2011 18:05
I am sorry, my bad...

Found that it wasnt the keychecking that was the problem, it was my "Responsive movement" part that had some old commands in it. It checked if player one released the up- or downkey, and only then the movement would stop. But since player one uses W and S, and its player two that uses Up- and downkey, it checked for player two's keys

But thanks! When implementing your code, DVader, I found these lost commands

Login to post a reply

Server time is: 2026-07-11 04:24:25
Your offset time is: 2026-07-11 04:24:25