Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Reading Virtual Key Codes with gets/fgets (http://www.go4expert.com/forums/reading-virtual-key-codes-fgets-t28118/)

netpumber 30Mar2012 19:35

Reading Virtual Key Codes with gets/fgets
 
Hello.

Lets say we have this code

Code:

char string [256];

printf("please write something here:\n");
gets(string);
printf("You typed:%s\n",string);

If user presses some letters those will be printed out latter. But how can we make this program understand that user pressed the Page Up button that its Virtual key code is "KEY_PPAGE" according to MSDN ?

Is there any way to do it ?

Thanks in advance.

netpumber 30Mar2012 20:14

Re: Reading Virtual Key Codes with gets/fgets
 
Sorry "VK_PRIOR " is the virtual key code of the page Up button.

xpi0t0s 31Mar2012 21:01

Re: Reading Virtual Key Codes with gets/fgets
 
You need to use a function that returns VK_ values, such as GetKeyState. gets is not one of those functions so you cannot use it for what you want to do.

Scripting 1Apr2012 02:30

Re: Reading Virtual Key Codes with gets/fgets
 
Quote:

Originally Posted by xpi0t0s (Post 93898)
You need to use a function that returns VK_ values, such as GetKeyState. gets is not one of those functions so you cannot use it for what you want to do.

Exactly. But if u want, you can write something like
Code:

if(GetKeyState(VK_PRIOR))
{printf("you pressed %s", string);}
else if (GetKeyState(VK_F5))
{etc.....}

It's only pseudocode...


All times are GMT +5.5. The time now is 15:55.