Thread: Mouse

  1. #1
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    California, US


    I searched the board, but haven't found anything that answers my question. How do you get mouse input in a console? I'm pretty sure this has been asked quite a few times from what I found during my search, but out of those I didn't get an answer. I know how to get things like arrow keys but not the mouse. So does anyone want to tell me (or again ) how to get mouse input. I'm using Dev-C++ and Windows ME (just in case). I know it's possible within a console, because I've seen a couple of programs with it. I couldn't find the code in these programs though. So, any help is helpful...

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    there's a couple ways to do it:

    1) use GetCursorPos and check the difference between the current and last position and then move the "selection" in the console by that much


    POINT lastPos;
    int dosPosX=0;
    int dosPosY=0;
    while(some condition)
    	POINT cursorPos;
    	dosPosX+=(cursorPos.x-lastPos.y)/8;  // Move one position for every 8 pixels the mouse changed
    // The code above might want to be changed, i just whipped this together right now and don't have time to test it (my battery is almost dead on my laptop :()
    // but this should work somewhat decently, just if they move less than 8 pixels per test, it won't move at all, so it would
    // be better to implement some sort of accumulator that would take the remainder and not throw it out
    2) another way is to research some Dos-development communities (if there really are any) and ask around for a better way to do this....

    -hope that helps

  3. #3
    Been here, done that.
    Join Date
    May 2003
    If you have a compiler that can use the interrupts from DOS, check out for interrupt 0x33
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004

    There are lots of tutorials on the Web

    If you search the web for "mouse input console" you should find several sites that have examples. Basically what you have is a function ReadConsoleInput. This function accepts a data structure called INPUT_RECORD which contains another data structure MOUSE_EVENT which tells you the state of you mouse. Right button clicked or x and y position. You create a handler routine to fetch the records one at atime just like in a normal windows application inspect each record if it is a mouse event then give it to a mouse handler if it is a keyboard event then you give it to the keyboard handler. I have a program I created in visual C++ that i was using to play aorund with the console maybe it can give you some ideas.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need Help in Mouse Pointer
    By obaid in forum C++ Programming
    Replies: 3
    Last Post: 12-07-2006, 03:33 AM
  2. Problem in mouse position
    By Arangol in forum Game Programming
    Replies: 6
    Last Post: 08-08-2006, 07:07 AM
  3. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 02:10 AM
  4. Making a mouse hover button, API style
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 05-27-2004, 06:17 AM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM