Results 1 to 4 of 4

Thread: trapping keys

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    trapping keys

    for school I have to make a function to trap all keys and the mouse buttons...msdn came up with nothing (again!)...the main keys are easy...
    Code:
    int trap()
    {
    	int ascii = getch();
    	return ascii;
    }
    but the mouse had nothing for checking clicks....and is there a better way to get keyboard input, like every key?
    this is a console app.

    thanks!

    (you don't have to write anything for me, just if you know any function names that would be fabulous!)


  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    ooooooooooh
    BOOL GetKeyboardState(PBYTE lpKeyState);

    sounds like its what I want for the keyboard at least....now anyone know how on earth to use it?

  3. #3
    Member
    Join Date
    Feb 2001
    Posts
    57
    Hi Steve! I decided to be really nice and solve both the keyboard and mouse problems. Here you go:

    PHP Code:

    #include <iostream.h>
    #include <windows.h>

    int main()
    {

        
    int keys[256];
        
        
    // Reset all key values
        
    for (int i 0256i++)
            
    keys[i] = 0;

        
    // Wait for the enter key or left mouse button
        // to be pressed
        
    while (keys[13] == && keys[VK_LBUTTON] == 0)
            for (
    0256i++)
                
    keys[i] = GetAsyncKeyState(i);

        
    // Print message
        
    cout << "Enter or mouse button was pressed" << endl;

        return 
    0;


  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    chilibean thanks so much! you really didn't have to!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width