Reading Virtual Key Codes with gets/fgets

Discussion in 'C' started by netpumber, Mar 30, 2012.

  1. netpumber

    netpumber New Member

    Joined:
    Nov 10, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. netpumber

    netpumber New Member

    Joined:
    Nov 10, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Sorry "VK_PRIOR " is the virtual key code of the page Up button.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
  4. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    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...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice