Thread: How do I use the Mouse and the Keyboard simultaneously?

  1. #1
    Registered User
    Join Date
    Aug 2019
    inside a singularity

    How do I use the Mouse and the Keyboard simultaneously?

    As the title may suggest, I'm having problems using the mouse and keyboard simultaneously.

    I'm a 12th grade student from India. I'm working on making a simple version of Gmail with graphics, some animations (basically making it look and presentable) and extensive file handling as part of my C++ project that students have to submit every year. I'm making it on Turbo C++ which is obviously (not, for my school at least) an ancient IDE with amazing features that doesn't include Multi-Threading....

    So, what I basically want is to be able to use the mouse on the screen and be able to perform selections (and all the other stuff which I might need the mouse for) as well as when the user starts to type something, be able to sense it and echo it on to the screen.

    This is what I've come to:

    while ( !kbhit() )
              if( kbhit() )
                        getche(); //echo to screen
                   //The mouse functions using union REGS  
    However, this isn't working (It only runs until the first key is pressed and then stops). I need help with knowing how both can be used simultaneously....

    I don't know of any way other than an infinite loop for using the mouse features in Turbo.
    Last edited by Zeus_; 08-11-2019 at 11:40 AM. Reason: Extra info added

  2. #2
    Registered User
    Join Date
    Feb 2019
    Hheheheh... it depends, if you are right handed, put your right hand over the mouse buttons, and the left one on the keyboard. For left handed people, the other way around can be easier...

    Seriously: There is no standard way to get the mouse data on MSVCRT##.DLL (Visual C++ Runtime) or libc. And kbhit() isn't a standard function as well....

    I recommend studying libraries like SDL (Simple DirectMedia Layer - here), and/or Win32 API (Windows, of couse).


  3. #3
    Registered User
    Join Date
    Dec 2017
    It only runs until the first key is pressed and then stops
    That's exactly what your loop says: "while no key has been pressed, keep looping" (i.e., stop as soon as a key is pressed).

    Presumably you want something more like:
        while (true) {
            if (kbhit()) {
                // handle keyboard stuff
            else if (mousehit()) {
                // handle moust stuff
    If "mousehit" (or something similar) doesn't exist then you need to write it. A quick google suggests it would use int86().

    But it's still a suboptimal method. We would usually let the program sleep until something happens instead of using an active loop.
    Philosophy is a battle against the bewitchment of our intelligence by means of language. - Wittgenstein

  4. #4
    Registered User
    Join Date
    May 2019

    There are so many absolutely free C++ compilers and IDE's that I have some trouble understanding why anyone would use TurboC++ unless targeting outdated operating system targets.

    What OS are you targeting?

    Aside from that point, however, @john.c's point is about a typical animation loop used in older DOS applications, but it does seem to be an infinite loop just taking keyboard and mouse input. There is more to the notion than that, however.

    It was typical prior to modern operating systems that, without threads, a "cooperative multi-tasking" approach to software design was implemented. This is still true to some extent in many game designs today. The idea is that an infinite loop processes each of several objectives (like input from keyboard, then input from mouse, then calculate the next frame of animation, then display).

    The challenge was always to keep each one of these phases very short. If any task took longer than some arbitrary amount of time, that task was designed to be paused and resumed at subsequent passes through the animation loop. This was typical of the ancient 16 bit Windows, DOS and early MAC operating systems (80's and 90's).

    Seriously, though, unless you must use Turbo C++, the limitations of that compiler block you from learning modern programming. That should have you searching for a replacement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP - disable keyboard/mouse
    By danielcplusplus in forum C++ Programming
    Replies: 6
    Last Post: 08-03-2015, 02:15 PM
  2. Activation for mouse and keyboard
    By underline_bruce in forum Windows Programming
    Replies: 1
    Last Post: 09-03-2007, 09:20 AM
  3. disable keyboard and mouse?
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 03-31-2006, 04:25 PM
  4. Moving the mouse around with the keyboard?
    By Queatrix in forum Tech Board
    Replies: 2
    Last Post: 05-10-2005, 11:21 AM
  5. locking mouse and keyboard in C
    By lepricaun in forum C Programming
    Replies: 4
    Last Post: 08-19-2004, 10:54 AM

Tags for this Thread