none
WM_KEYDOWN

    Question

  • Hello, I am looking for some help on making a program that will give me the number for each key.  I known that I need to hook the keyboard first, and I have that code.  Now, from there I am oblivious as to what I need to do next.  Any refrences or sample codes would be great.  Thanks.  Note: Win32 API is what was writing this in.  If I can possibly stick to that, it would be great.  Thank you.  (This is NOT for a homework assignment, instead I was curious about the keyboard's numbering, for all combinations)

    ctimko
    Saturday, March 04, 2006 2:39 AM

Answers

  •  ctimko wrote:
    Hello, I am looking for some help on making a program that will give me the number for each key.  I known that I need to hook the keyboard first, and I have that code.  Now, from there I am oblivious as to what I need to do next.  Any refrences or sample codes would be great.  Thanks.  Note: Win32 API is what was writing this in.  If I can possibly stick to that, it would be great.  Thank you.  (This is NOT for a homework assignment, instead I was curious about the keyboard's numbering, for all combinations)

    ctimko

    You don't need to install a hook. As in your subject line, handling WM_KEYDOWN should be good enough. wParam will give you the virtual key code for that key.

    Saturday, March 04, 2006 6:29 AM
  • Cast the wParam to an int, use sprintf to put that value into a char buffer, and use MessageBox.

     ctimko wrote:

    What I mean is..is the code like this?

    if (WM_KEYDOWN = = 9)

    {

        CreateWindow("STATIC","9",WS_VISIBLE|WS_CHILD,0,0,100,20,hwnd,0,hThisInstance,0);

    }else{

    CreateWindow("Static", "something else", WS_VISIBLE|WS_CHILD,0,0,100,20,hwn,0,hThisInstance,0);

    }

     

     

    Is this what you mean?  I can't seem to get it to work.  Should I use a message box instead?  Would that give me a different result?  I am using the old Win32 API

     

    Thursday, March 16, 2006 4:36 PM

All replies

  •  ctimko wrote:
    Hello, I am looking for some help on making a program that will give me the number for each key.  I known that I need to hook the keyboard first, and I have that code.  Now, from there I am oblivious as to what I need to do next.  Any refrences or sample codes would be great.  Thanks.  Note: Win32 API is what was writing this in.  If I can possibly stick to that, it would be great.  Thank you.  (This is NOT for a homework assignment, instead I was curious about the keyboard's numbering, for all combinations)

    ctimko

    You don't need to install a hook. As in your subject line, handling WM_KEYDOWN should be good enough. wParam will give you the virtual key code for that key.

    Saturday, March 04, 2006 6:29 AM
  • So, then how would I set the code up??
    Friday, March 10, 2006 6:30 PM
  •  ctimko wrote:
    So, then how would I set the code up??

    What do you mean by "set the code up" ?

    Saturday, March 11, 2006 12:50 PM
  • What I mean is..is the code like this?

    if (WM_KEYDOWN = = 9)

    {

        CreateWindow("STATIC","9",WS_VISIBLE|WS_CHILD,0,0,100,20,hwnd,0,hThisInstance,0);

    }else{

    CreateWindow("Static", "something else", WS_VISIBLE|WS_CHILD,0,0,100,20,hwn,0,hThisInstance,0);

    }

     

     

    Is this what you mean?  I can't seem to get it to work.  Should I use a message box instead?  Would that give me a different result?  I am using the old Win32 API

     

    Thursday, March 16, 2006 4:27 PM
  • Cast the wParam to an int, use sprintf to put that value into a char buffer, and use MessageBox.

     ctimko wrote:

    What I mean is..is the code like this?

    if (WM_KEYDOWN = = 9)

    {

        CreateWindow("STATIC","9",WS_VISIBLE|WS_CHILD,0,0,100,20,hwnd,0,hThisInstance,0);

    }else{

    CreateWindow("Static", "something else", WS_VISIBLE|WS_CHILD,0,0,100,20,hwn,0,hThisInstance,0);

    }

     

     

    Is this what you mean?  I can't seem to get it to work.  Should I use a message box instead?  Would that give me a different result?  I am using the old Win32 API

     

    Thursday, March 16, 2006 4:36 PM
  • So, am I still using the if...else statements?  Sorry if I am driving you crazy.  I am teaching myself the hardest language and I just need to understand whats happening.  :P
    Friday, March 17, 2006 1:32 AM
  •  ctimko wrote:
    So, am I still using the if...else statements?  Sorry if I am driving you crazy.  I am teaching myself the hardest language and I just need to understand whats happening.  :P

    It's alright - everyone starts somewhere :-)

    But in your case, I am not sure I fully understand what you are trying to do. My understanding is that, you are writing a program that will show the virtual key codes for select keys. Is that right? Or are you trying to do something else?

    Friday, March 17, 2006 2:42 AM
  • I am working on a program that will give me the Hex Decimal for the key that is pressed on the keyboard.  I have a really big keyboard at home that is something like 205 keys and I am trying to find out what everything is. Does that make any sense?
    Monday, March 20, 2006 6:45 PM
  •  ctimko wrote:
    I am working on a program that will give me the Hex Decimal for the key that is pressed on the keyboard.  I have a really big keyboard at home that is something like 205 keys and I am trying to find out what everything is. Does that make any sense?

    Getting the virtual key code is easy, but to display it won't be that easy, since you are using pure API and seem to be totally new to C++ and Win32 coding.

    My best advice to you is to get Charles Petzold's book - Programming Windows 5th edition. Do it before MS Press makes it out of print - they have been doing that to some of their non-.NET books :-)

    Monday, March 20, 2006 7:06 PM
  • Finding the book isn't easy.  I have gone to many stores looking for that, and many stores show that it is out of print already.  I have been programming in C++ and Win32 for about 2 years, but I have never tried taking risks.  I was doing basic programs and trying to master a level before I moved on.  I am now designing a program that blocks keypresses, but the keyboards that we are using aren't common keyboards.  So thats where this program comes in.  Now for the wParam to int do I use a pointer?  I know the sprintf function, and infact I use it alot.  I learn best when I can see a little sample of the code.  So, if you can show me a little bit of what your talking about earlier, I will have no problem understanding it.  I am not very knowledgable of the lingo programmers use as I should be, but thats what you get for not owning a book by Petzold.
    Wednesday, March 22, 2006 3:21 AM
  •  ctimko wrote:
    Finding the book isn't easy.  I have gone to many stores looking for that, and many stores show that it is out of print already.  I have been programming in C++ and Win32 for about 2 years, but I have never tried taking risks.  I was doing basic programs and trying to master a level before I moved on.  I am now designing a program that blocks keypresses, but the keyboards that we are using aren't common keyboards.  So thats where this program comes in.  Now for the wParam to int do I use a pointer?  I know the sprintf function, and infact I use it alot.  I learn best when I can see a little sample of the code.  So, if you can show me a little bit of what your talking about earlier, I will have no problem understanding it.  I am not very knowledgable of the lingo programmers use as I should be, but thats what you get for not owning a book by Petzold.

    Alright, here's some sample code

    case WM_KEYDOWN:
     TCHAR buff[10];
     _stprintf(buff, _T("%d"), (int)wParam);
     SetWindowText(hWnd,buff);
     break;

    For each key that's pressed, the virtual key code is shown as the window title. You may want to insert that to a listbox or maybe an edit control.

    Wednesday, March 22, 2006 5:24 PM
  • thank you very much...sorry for being a pain.  I guess i was trying to hard and wasn't thinking easy.  could you just explain one thing to me, what does (int)wParam mean? Does it mean that whatever is in wParam, put into an integer form and then store it into the buff?  Let me know if i understood that right.  And thank you very much, it helps alot and there doesnt seem to be any problems.

    ctimko
    Sunday, April 16, 2006 10:06 PM
  • so if I wanted to take that snipet of sample code and put it into a switch statement with cases that depend on what key is pressed how would that switch look?
    Sunday, September 10, 2006 5:55 AM