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 / Simple input from the sample gdk wizard for c++

Author
Message
JohnA
13
Years of Service
User Offline
Joined: 20th Jul 2011
Location: The second star on the right
Posted: 20th Jul 2011 10:01
this code is what is in the sample
if ( dbUpKey ( ) )
dbMoveCamera ( 1 );

I am simply playing around trying to make this code to have the w key pressed to make the camera go forward. I am inbarsed that i've spen a couple hours and i just cant get it right.
if (dbKeyState(w));
dbMoveCamera ( 1);
just doesn't work. I felt like doing a getc funchure lol i am stumpped. I what to be able to program in c++ but i chan't get past this, it's going to be a long tiome before i can do anything that i have in mind and written out. pleas help before i pull out the hair i have left, which isn't much lol

John
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 20th Jul 2011 11:49 Edited at: 20th Jul 2011 11:52
dbKeyState expects an integer number which is the SCAN CODE of the key pressed. (See the description in the help.) It won't accept a character, or if it does, it will convert it to integer and that won't do what you expect. (You just wrote w which is not even a character constant: without apostrophes, the system would try to interpret it as a variable name.)

So you have to know what's the scan code of the W key. You can see the full, predefined list of scan codes in the "dinput.h" header file, which you can find in the directory where you installed the DirectX SDK (by default in Program Files), in the Include subdirectory. To use the predefined constants, you can either #include dinput.h - but I found this gives compiler warnings, or you can just copy out the codes you need, and put it into your program.

In that list you can find that the scan code of W is:



In case you are wondering, 0x11 is a hexadecimal number (would be 17 in decimal). If you have this constant defined, you can use it like:



Oh yes, one more thing. Don't put a semicolon between your "if" statement and dbMoveCamera, because it separates the "if" from the next line, making them two different statements. That means that the "if" won't do anything at all, while dbMoveCamera will always be executed.

That's why I dislike it when people break one-line "if" statements into two lines because it tempts you to make mistakes like this. Write a one-line "if" statement in one line (as above), or if you like to break it, then use braces. It's a question of style but I think it's helpful.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 20th Jul 2011 12:51 Edited at: 20th Jul 2011 12:53
Here is the full path to dinput.h, if the DirectX SDK is installed in the default directory:



The (x86) is in the path if you use a 64-bit Windows, otherwise it's probably just Program Files. Inside the file, search for DIK_ to find the list of scan codes.
JohnA
13
Years of Service
User Offline
Joined: 20th Jul 2011
Location: The second star on the right
Posted: 21st Jul 2011 06:28
thank you Mireben for you solution. I can do more coding to reach my goal.

Login to post a reply

Server time is: 2024-11-19 08:33:08
Your offset time is: 2024-11-19 08:33:08