Thread: How to disable a mouse in a console

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question How to disable a mouse in a console

    Hi!

    I noticed that if I have a mouse enabled in my console program and even if I do not move the mouse, it's still moving in some way (it seems that windows are refreshing the mouse every 500ms, i think).
    I know this beacuse I'm checking the MOUSE_MOVED message.
    I was checking the MSDN library but I found nothing.

    Anyone knows how to disable a mouse in a console with the WINAPI functions?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Registered User alpha561's Avatar
    Join Date
    May 2002
    Posts
    18
    Rather than that, couldn't you just make it so the user can only use the keyboard (i.e.- don't provide any mouse support)?
    alpha561

    "You don't want to sell me death sticks"

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    To kill the cursor on a console I think you need to be in full screen mode......

    You might want to look at a full Win32 app if you want more functionality

  4. #4
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    alpha561

    NO WAY! The keyboard and the mouse are already completely coded. Now, I'm debbuging some things, like this for example.

    Fordy
    You misunderstood the question. I do not want to kill the cursor, I just want to disable the mouse.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Then you want to stop the system sending your app mouse messages?....

    You cant!! That is beyond the scope of your application....

    What problem is it causing you?

  6. #6
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    There must be a way. I read something about the MOUSE_ENABLE_INPUT in the MSDN library but I don't know if this is it.

    The problem is, uf that will be hard to explain. You try that and you'll get it.

    Point your mouse on the menu, doesn't matter in which application you'll do that, click the command (FILE menu for example) and the menu will expand (will be opened). Now if you go with your mouse over some command, the command will than be selected. Now you leave your mouse alone and just use the keyboard (keys UP and DOWN) for selecting other commands. Now you see that, let's say, when you leave your mouse alone it was pointing on a command A. Then you press a key (UP or DOWN) and now the selected command is command B. In Windows application you'll notice that the command A will never get selected until you'll move the mouse or use the keyboard.
    This is the problem in my console application. The mouse is pointing on a command A and when I use the keyboard, the command B will get selected but after 0.5 s, the command A will be again selected.

    I hope this will help you to understand better my problem .
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  7. #7
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    Not sure how accurate this is but you can set the console mode
    Code:
    SetConsoleMode( hStdin, ENABLE_LINE_INPUT );
    where hStdin is a handle to the input buffer, this should stop the mouse messages from being placed in the input buffer. So just call this function when you want to ignore the mouse, to reactivate the mouse use
    Code:
    SetConsoleMode( hStdin, ENABLE_MOUSE_INPUT );
    check out your docs though as there are other macros you can use ofr different needs.
    Hope that helps
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  8. #8
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    I think this is the way but I have one HUGE problem. When the user is using the keyboard (UP, DOWN and RETURN keys) then the mouse will be disabled. And if the user is using mouse the keyboard will be disabled. I think this is impossible to code, beacuse if I disable the mouse, then how to enable it when the mouse moved or the button was clicked if the mouse is disabled?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console Mouse and Key Input
    By Yuri in forum C++ Programming
    Replies: 3
    Last Post: 02-18-2006, 04:56 PM
  2. Change colour of screen and disable mouse
    By Meesa in forum C Programming
    Replies: 2
    Last Post: 05-18-2004, 07:55 AM
  3. Mouse Wheel In Console
    By GaPe in forum C Programming
    Replies: 0
    Last Post: 09-07-2002, 02:05 AM
  4. Mouse support in console mode
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 04-17-2002, 05:15 AM
  5. Mouse in console
    By vasanth in forum C++ Programming
    Replies: 0
    Last Post: 02-05-2002, 11:32 PM