Sign in to follow this  
Joshnathan

Mouse Problem

Recommended Posts

Hi all, I am trying to create a menu for my text based rpg game, but when I try to use it in Full screen mode, it doesn't work. Here is my menu():
void menu(int couleur)
{
    system("cls");
    HANDLE handle_input;
    HANDLE handle_output;
    INPUT_RECORD input_record;
    DWORD events;
    handle_output = GetStdHandle(STD_OUTPUT_HANDLE);
    handle_input = GetStdHandle(STD_INPUT_HANDLE);
    SetConsoleTextAttribute(handle_output, FOREGROUND_RED);
    if(couleur == 1)
    SetConsoleTextAttribute(handle_output, FOREGROUND_RED | BACKGROUND_BLUE);
    cout<< "1.Lire le Journal";
    SetConsoleTextAttribute(handle_output, FOREGROUND_RED);
    cout<< endl;
    if(couleur == 2)
    SetConsoleTextAttribute(handle_output, FOREGROUND_RED | BACKGROUND_BLUE);
    cout<< "2.Regarder la Carte";
    SetConsoleTextAttribute(handle_output, FOREGROUND_RED);
    cout<< endl;
    if(couleur == 3)
    SetConsoleTextAttribute(handle_output, FOREGROUND_RED | BACKGROUND_BLUE);
    cout<< "3.Changer de Lieu";
    SetConsoleTextAttribute(handle_output, FOREGROUND_RED);
    cout<< endl;
    cout<< "Entrez votre choix:\n"; 
    
    LireInput();

}    

void LireInput()
{
    HANDLE handle_input;
    HANDLE handle_output;
    INPUT_RECORD input_record;
    DWORD events;
    handle_output = GetStdHandle(STD_OUTPUT_HANDLE);
    handle_input = GetStdHandle(STD_INPUT_HANDLE);
    ReadConsoleInput(handle_input, &input_record, 1, &events);
    
    if(input_record.EventType == KEY_EVENT && input_record.Event.KeyEvent.bKeyDown)
    {    
        switch(input_record.Event.KeyEvent.wVirtualKeyCode)
        {
            case 49: LireJournal();
                    break;
            case 50: carte();
                    break;
            case 51: ChangerLieu();
                    break;
            default:cout<< "Erreur, choix pas valable.";
                    Sleep(1000);
                    menu(0);
                    break;
        }
    }  
  if(input_record.EventType == MOUSE_EVENT)
  {
      if(input_record.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
      {
          
                if((input_record.Event.MouseEvent.dwMousePosition.X < 20)  && (input_record.Event.MouseEvent.dwMousePosition.Y == 0))
                {
                LireJournal();
                return;
                }
                else if((input_record.Event.MouseEvent.dwMousePosition.X < 20)  && (input_record.Event.MouseEvent.dwMousePosition.Y == 1)) 
                {
                carte();
                return;
                }    
                else if((input_record.Event.MouseEvent.dwMousePosition.X < 20)  && (input_record.Event.MouseEvent.dwMousePosition.Y == 2)) 
                {
                ChangerLieu();
                return;
                }  
                else
                {
                LireInput();
                }
                
      }   
      
          
                if((input_record.Event.MouseEvent.dwMousePosition.X < 20)  && (input_record.Event.MouseEvent.dwMousePosition.Y == 0))
                {
                menu(1);
                }
                else if((input_record.Event.MouseEvent.dwMousePosition.X < 20)  && (input_record.Event.MouseEvent.dwMousePosition.Y == 1)) 
                {
                menu(2);
                }    
                else if((input_record.Event.MouseEvent.dwMousePosition.X < 20)  && (input_record.Event.MouseEvent.dwMousePosition.Y == 2)) 
                {
                menu(3);
                }  
                else
                {
                LireInput();
                }
                     
  }  
} 

it works fine when I run it in windowed mode, but in full screen the cursor ALWAYS comes back to the middle of the screen. I can't get the mouse up the my menu and actually click. I can try, but before I reach my menu I am back in the middle of the screen. [Edited by - Joshnathan on November 9, 2004 9:56:28 AM]

Share this post


Link to post
Share on other sites
Looks like you are re-initilizing your INPUT_RECORD input_record
every time you call your mouse function, which in might reset it every time its called.

My advice is to move it into a global, so that it's information stays valid throughout your program.

I really don't know if that will fix it. Looks like it should work the way it is. Also make sure your not resetting your mouse coords somewhere else in the code.

Another idea I would use to figure out whats going on, is write out the mouse coords to the screen every frame if you can to see what is going on with the mouse.

Share this post


Link to post
Share on other sites
I think I may know the problem! (I hope so ;)
I think it is the system("cls"), but does anyone know of a way to clear the screen another way then system("cls")?

I hope this is a question much easier to answer then my first one ^^

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this