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 Discussion / Keyboard Control

Author
Message
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Sep 2007 03:28
It's Insert Name Here's pic and he had it on crappy media fire

In programming, nothing exists
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Sep 2007 12:56
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 28th Sep 2007 13:04
I've got it working at last!!!!!!

<Brief pause as Robert the Robot does one hundred somersaults around the room in jubilation>

<Longer pause as Robert the Robot wonders why there are now a load of wheels and gears all over the floor>

I'd stumbled across one way of eradicating the red line when shift/upkey was pressed - I accidentally set the CanPressKey(0) array to always be zero. But the single keystrokes wouldn't work - they were only detected if CanPressKey(0) = 1.

I had to reset the canPressKey(0) at some point, and after a lot of fiddling and rearranging,I produced this:




It only works if you check for two-key and then one-key combinations (don't ask me why, I'm still trying to figure it out myself). The case statements check which two key combination is being pressed, and if it finds one that is, it bypasses all other keyboard checks.

The only thing is, I can't help feeling the code is a bit messy. I'm trying to condense the two-key case statment block into a single function, but is it possible to condense the whole thing down? I could do with some help here, and on Functions in general - I never could quite get the hang of them...


@ Latch

Your code was a very good idea, but I was a little bothered by the fact that your example seemed to hard-code in how many keys would be assigned to each command. The way it stands at the moment, if you wanted to draw red lines then whatever you did, you'd press one key. If you wanted green lines, you'd always have to press two keys.

I did try to change that, but I wound up covering the screen with red and green lines. Oops...

On our way 'ome, on our way 'ome...
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Sep 2007 22:31
Quote: "Your code was a very good idea, but I was a little bothered by the fact that your example seemed to hard-code in how many keys would be assigned to each command"


That's why I was originally suggesting the set bits method. You could press 10 keys if you want and by setting the bits in a variable, you only have to look at one final value for your program to respond to.

That last example I gave you is just a quick and dirty method. It assumes you would have a standard number of keypresses for an action.

You could modify that method to accept as many keys as you want I suppose, then you could use a variation of your original method and the example. But since you already solved it, this may be useful for something else.

psuedo code:


Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Sep 2007 16:58
@RoboRob
What is this for?

In programming, nothing exists
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 1st Oct 2007 13:18
@Latch
Very interesting, it may well come in handy...

@OBese87
This is all for a program I made called Lightning Lights - something that lets you create lighting effects for your 3D levels and export them as DBC/DBPro source code. My Beta Testers didn't think much of my default keyboard commands, so I wanted to let them customise things...

On our way 'ome, on our way 'ome...

Login to post a reply

Server time is: 2025-05-31 21:32:53
Your offset time is: 2025-05-31 21:32:53