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.

Geek Culture / Anyone familiar with C++ here?

Author
Message
HZence
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 5th May 2004 22:12 Edited at: 5th May 2004 22:13
Very basic question (with an answer that is probably complicated): How can I determine what key is being pressed on the keyboard? I know how to detect a basic keypress. I just don't know how to tell which. Here's the function I use:



Any help is appreciated...thanks.


Team EOD :: Programmer/Storyboard Assistant
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 5th May 2004 22:52 Edited at: 5th May 2004 22:54
Well in C++ there are several ways to achieve it;
as i don't cross platform program I use the Windows Message system like this:



you can assign whatever keys you like to them simply by doing

bKey['w'] = w
bKey['W'] = W
bKey[VK_NUMPAD1] = 1 on the numberpad
bKey[VK_1] = 1 above the keys

if you want to check them all simple do a for((int)i=0; i=>255; i++){ };

and if you want to add support for Asian language keyboards simply extend it to bKey[256^2]

[additional] doing it this way also allows you to actually have different keysets for different windows. this is very useful when application developing; as you can reuse hotkeys, and those keys pressed do not affect others.

but as i said there are multiple ways to do it.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
SonicBoom
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 5th May 2004 22:53
I would suggest to either use DirectInput or GetAsyncKeyState...

HZence
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 5th May 2004 22:58
Thanks guys.

Unfortunately I'm at schol right now and it's near the end of the day so I won't get to try it 'till tomorrow. (I need it for a C++ Project).

Thanks again!

More input appreciated as well.


Team EOD :: Programmer/Storyboard Assistant
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 6th May 2004 12:47
Quote: "Anyone familiar with C++ here?"


If you mean the programming language, then yes. It looks like you've got multiple solutions to your problem though (both look correct too) so I guess I can't help anyway.


"Computers are useless they can only give you answers."
HZence
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 6th May 2004 23:43
@Raven: What is 'LResult'? CodeWarrior doesn't recognize it.


Team EOD :: Programmer/Storyboard Assistant
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 7th May 2004 00:01
LResult is the low 16bit result of a 32bit result, just like HResult is the high 16bit.
bitshifting will get it, but my brain has gone to mush atm cause i'm working on a new model for something;

but hopefully you'll figure out howto get it.


AthlonXP 2500+ | 256MB DDR PC2700 | GeForce FX 5200 44.04 | DirectX 9.0 | Audigy2 | Crystal Clean OS
HZence
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 7th May 2004 00:13
Well if it wasn't for the whole LResult thingy I think I would. (If you couldn't tell I'm not exactly a seasoned C++ coder. Heh.)

Would that code need to go inside a function or something? Does it require a specific header?


Team EOD :: Programmer/Storyboard Assistant
Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 7th May 2004 00:53
The reason CodeWarrior doesn't recognise it is probably because it is LRESULT not LResult if you are using the windows header files (where all constants are spelt with caps)

However I recommend SonicBoom's suggested method.

BlueGUI:Windows UI Plugin - All the power of the windows interface in your DBPro games. - Plus URL download, win dialogs.
Over 140 new commands
HZence
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 7th May 2004 02:31
Alright, thanks Rob. And come to think of it, that actually makes sense, considering wParam in CodeWarrior is WPARAM. Should have known...


Team EOD :: Programmer/Storyboard Assistant

Login to post a reply

Server time is: 2024-11-25 05:13:37
Your offset time is: 2024-11-25 05:13:37