Thread: Console Mouse and Key Input

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    Console Mouse and Key Input

    Hi.
    I created a little code that reads the input of the user by mouse and by key input. I actually couldn't really find any real usefull code only after a long search on msdn. I made this code for an example, to test if it is possible to read the user his mouse and key input and still have an never-ending-loop going on, and it worked. I will use this in my big project but I guessed it may come usefull for others. It's very easy and clear code and not that spagetti code from msdn, :P. I hope it may come usefull for you too.

    PHP Code:
    #include <iostream>
    #include <windows.h>

    using namespace std;

    bool Mouse_On;

    KEY_EVENT_RECORD Key;

    MOUSE_EVENT_RECORD Mouse;

    INPUT_RECORD Record_Input;

    DWORD Input_Size,
                 
    Event_Count;

    int main()
    {

        
    cout<< endl<< endl<< "Click on [HERE]";

        
    Mouse_On false;

        while ( 
    EOF )
        {

            
    GetNumberOfConsoleInputEvents GetStdHandle STD_INPUT_HANDLE ), & Event_Count );

            if ( 
    Event_Count != )
            {

                
    ReadConsoleInput GetStdHandle STD_INPUT_HANDLE ), & Record_Input1, & Input_Size );

                if ( 
    Record_Input.EventType == KEY_EVENT )
                {

                    
    Key Record_Input.Event.KeyEvent;

                    if ( 
    Key.bKeyDown == true )
                    {

                        if ( 
    Key.wVirtualKeyCode == VK_RIGHT )
                        {

                            
    cout<< endl<< endl<< "Right arrow";
                        }

                        else if ( 
    Key.wVirtualKeyCode == VK_LEFT )
                        {

                            
    cout<< endl<< endl<< "Left arrow";
                        }

                        else if ( 
    Key.wVirtualKeyCode == VK_RETURN )
                        {

                            
    cout<< endl<< endl<< "Enter key";
                        }
                    }
                }

                else if ( 
    Record_Input.EventType == MOUSE_EVENT )
                {

                    
    Mouse Record_Input.Event.MouseEvent;

                    if ( 
    Mouse.dwMousePosition.>= &&
                          
    Mouse.dwMousePosition.<= 14 &&
                          
    Mouse.dwMousePosition.== )
                    {

                        if ( 
    Mouse.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED )
                        {

                               
    cout<< endl<< endl<< "You clicked on [HERE]";
                        }

                        else if ( 
    Mouse_On == false )
                        {

                            
    cout<< endl<< endl<< "Click now on [HERE]";

                            
    Mouse_On true;
                        }
                    }

                    else if ( 
    Mouse_On == true )
                    {

                        
    Mouse_On false;
                    }
                }
            }

            
    Sleep 100 );
        }

    Last edited by Yuri; 02-17-2006 at 01:43 PM.

  2. #2
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Didn't know this was useless, . I really thought this could help out other people, well you can delete this thread then, .

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    1
    hi!

    well.. I just started to learn how to program c++.. (day 4 at the learn c++ in 21 days hehe).. and I just want you to know that even if this is not for me to use now.. I want to encourage you to always try to help.. someday this can be usefull for me.. or for many people.. just wait

    but... thanks for the help in the forum anyway!

  4. #4
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Ok, thanks. It probably will be usefull for someone. And it will be easy to find on this forum.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  2. Game console input
    By glUser3f in forum Game Programming
    Replies: 3
    Last Post: 11-07-2003, 04:33 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM