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.

Dark GDK / Keyboard/Mouse Input class

Author
Message
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 19th Jan 2010 23:55 Edited at: 3rd Feb 2010 00:38
I already have this posted in the code snippets board, but I wasn't sure if anybody that uses DarkGDK really goes there often since the majority of posts there are for DBP. So here it is.

Tools:



and Input:



(The only reason I'm putting Tools on this is because Input::InputState relies on it)

The Input::InputState class takes input to a new level and makes everything a lot easier, instead of just using dbKeyState() and dbMouseClick(). It can check if a (virtual) key is:
-Pressed
-Held(true after one loop after of being pressed)
-Down(pressed or held)
-Up(not pressed or held)
-Released(true for one loop after the key is released)
-DoubleClick(WORKS WITH KEYBOARD AND MOUSE!!! (Every virtual key))

The namespaces also do not rely on DarkGDK one bit, so you can use them in any application (although, Input classes need the windows message pump, so they will not work in a console application)

Comments were made with AtomineerUtils, if anyone is wondering.

Attached is the project for creating a static library with an example project.

Tell me what you think!

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;

Attachments

Login to view attachments
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 22nd Jan 2010 17:57
This looks awesome, everyone needs to do this kind of thing at some point in their game/engine so this could come in real handy.
It puts my attempt at this kind of thing to shame lol.

Have not got time to try it out yet, exams.

I don't know if we could use this in dosp for S3GE as I think Techlord is doing the input, I will mention it to him though.

One question, I have only browsed through it but when you update keyboard, does it iterate through every key or is there a way of only updating the keys relevant to your game?
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 22nd Jan 2010 21:38 Edited at: 22nd Jan 2010 22:25
That's actually one of the things I started thinking about right after I posted this.

It actually updates all 255 keys, which is really unnecessary, so I recently made an option for only updating the keys that have been checked for being down/pressed/etc. It stores whether each key has been activated, and only updates the ones that are activated, when FastUpdate() is called.

Here's the new project.

EDIT: IsKeyActive(), ActivateKey(), and DeactivateKey() added.

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;

Attachments

Login to view attachments
Freedom Fighters
14
Years of Service
User Offline
Joined: 2nd Nov 2009
Location:
Posted: 22nd Jan 2010 22:59 Edited at: 23rd Jan 2010 01:12
looks awesome. im going to try it out for my game. looks like it may make things easy for me. nice job.

EDIT: how do i use it in my project?

Problem Solution That Never Fails: "Build A Bridge And Get Over It"
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 23rd Jan 2010 03:23 Edited at: 23rd Jan 2010 03:25
Well, you can compile it (into a .lib file) and then include it into your project by one of three ways.

First, compile Utilities in Release mode, then open your project that you are trying to use Utilities with.

1 - (The global option)(and the easiest! ) - Go to Tools->(Options...)->[+]Projects and Solutions->(VC++ Directories) and choose 'Include files' from the drop down menu. Click the new folder icon and then click the three dot button [...] on the right side. Navigate to the Utilities folder and select "<...>\Utilities\Utilities". Now select "Library files" from the drop down list and repeat the process, but this time, choose "<...>\Utilities\Release". Now click OK. You are done! Now just include "Utilities.h" at the top of your project, or any other project, and it should work if done correctly.

2 - (The semi-global option) - Go to the solution explorer window and right click your solution file for the project you would like to use Utilities in. Click Add->(Existing Project...). Now navigate to where you have the Utilities folder and select this file: "<...>\Utilities\Utilities\Utilities.vcproj". Now just include "Utilities.h" at the top of your program that you wish to use Utilities with. You are done, and can edit the Utilities project and recompile it along with your program. You must repeat this for every new project you start if you want to use Utilities in more programs.

3 - (The local option) - Just copy/paste "Utilities.h", "Utilities.cpp", "Tools.h", and "Input.h". Include them into your project and just use them like any regular .h and .cpp files. Make sure the runtime is set to /MT. Done.

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Freedom Fighters
14
Years of Service
User Offline
Joined: 2nd Nov 2009
Location:
Posted: 23rd Jan 2010 11:08
ok i choose your third option.

how do i then use it. i tried the code from the demo and it dont work. what do i need do to make it work. i use like 6 class for each part of my program that need the key imputs, can it be global?

Problem Solution That Never Fails: "Build A Bridge And Get Over It"
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 23rd Jan 2010 17:27
Well make sure the files are included within the solution explorer window. (click "Show all files" and then right-click each one and select "Include in project", then click "Show all files again" - the files you included should stay)

What's the error?

If you want to use a global variable across multiple files, just use extern.

main.cpp


classes.h


classes.cpp


Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Freedom Fighters
14
Years of Service
User Offline
Joined: 2nd Nov 2009
Location:
Posted: 24th Jan 2010 02:43
ok. i did what you said but got this error


Problem Solution That Never Fails: "Build A Bridge And Get Over It"
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 24th Jan 2010 03:09
Whoops - change classes.cpp:

classes.cpp


That should work.

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Freedom Fighters
14
Years of Service
User Offline
Joined: 2nd Nov 2009
Location:
Posted: 24th Jan 2010 03:15
thanks. now it works. awesome.

Problem Solution That Never Fails: "Build A Bridge And Get Over It"
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 3rd Feb 2010 00:38 Edited at: 3rd Feb 2010 00:38
Newer version with some fixed bugs.

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-10-01 23:37:56
Your offset time is: 2024-10-01 23:37:56