• Advertisement
Sign in to follow this  

[Solved] Console: Any way to distinguish between number keys and numpad?

This topic is 3291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Edit: Typical. Been messing with this for about an hour and a half (thought I had some horrible bug before I realised the numpad and number keys were being treated the same), all to find there's unnamed VK codes for the keys. :/ Sorry! :) Hey guys, Just as the topic says, is it possible to distinguish between the key press of a number key and a numpad key? I'm chucking together a really simple paint program in a console app. so I can create content for my text RPG. It's quick and dirty (didn't want to spend much time on it) and here's the relevant code:
// ...snip...
if (c == '1') fgColour = FRED;
else if (c == '2') fgColour = FGREEN;
else if (c == '3') fgColour = FBLUE;
else if (c == '4') fgColour = FCYAN;
else if (c == '5') fgColour = FMAGENTA;
else if (c == '6') fgColour = FYELLOW;
else if (c == '7') fgColour = FGREY;

if (w == VK_NUMPAD0) bgColour = 0;
else if (w == VK_NUMPAD1) bgColour = BRED;
else if (w == VK_NUMPAD2) bgColour = BGREEN;
else if (w == VK_NUMPAD3) bgColour = BBLUE;
else if (w == VK_NUMPAD4) bgColour = BCYAN;
else if (w == VK_NUMPAD5) bgColour = BMAGENTA;
else if (w == VK_NUMPAD6) bgColour = BYELLOW;
else if (w == VK_NUMPAD7) bgColour = BGREY;

colourFlags = bgColour | fgColour;
SetConsoleTextAttribute(hOut, colourFlags);

// ...snip...

The problem is that fgColour will get set every time, because as I say, I can't distinguish between a number key and a numpad key. Is there any way around this or am I going to have to turn this into a win32 app., attach a console to the process and handle everything via WM_KEYDOWN?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement