Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Handling mouse using OS interrupts

Handling mouse using OS interrupts

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++comgame-dev
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    You should post your question in the forum at the end of the article so the author gets notified.

    Veni, vidi, abiit domum

    M Offline
    M Offline
    myth1990
    wrote on last edited by
    #3

    Thanks Richard, I couldn't think of that earlier. Thanks again

    1 Reply Last reply
    0
    • L Lost User

      You should post your question in the forum at the end of the article so the author gets notified.

      Veni, vidi, abiit domum

      S Offline
      S Offline
      Software_Developer
      wrote on last edited by
      #4

      OS interrupts are only used in 16-bit MSDOS apps. More [here ] You can try this code for a WIN32 console app.

      #include #include using namespace std;

      int main()
      {
      HANDLE hIn;
      HANDLE hOut;
      COORD KeyWhere;
      COORD MouseWhere;
      COORD EndWhere;
      bool Continue = TRUE;
      int KeyEvents = 0;
      int MouseEvents = 0;
      INPUT_RECORD InRec;
      DWORD NumRead;

      hIn = GetStdHandle(STD\_INPUT\_HANDLE);
      hOut = GetStdHandle(STD\_OUTPUT\_HANDLE);
      
      cout << "Key Events   : " << endl;
      cout << "Mouse Events : " << flush;
      
      KeyWhere.X = 15;
      KeyWhere.Y = 0;
      MouseWhere.X = 15;
      MouseWhere.Y = 1;
      EndWhere.X = 0;
      EndWhere.Y = 3;
      
      while (Continue)
      {
          ReadConsoleInput(hIn,
                           &InRec,
                           1,
                           &NumRead);
      
          switch (InRec.EventType)
          {
          case KEY\_EVENT:
              ++KeyEvents;
              SetConsoleCursorPosition(hOut,
                                       KeyWhere);
              cout << KeyEvents << flush;
              if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
              {
                  SetConsoleCursorPosition(hOut,
                                           EndWhere);
                  cout << "Exiting..." << endl;
                  Continue = FALSE;
              }
              break;
      
          case MOUSE\_EVENT:
              ++MouseEvents;
              SetConsoleCursorPosition(hOut,
                                       MouseWhere);
              cout << MouseEvents << flush;
              break;
          }
      }
      
      return 0;
      

      }

      More : [here ]

      M L 2 Replies Last reply
      0
      • S Software_Developer

        OS interrupts are only used in 16-bit MSDOS apps. More [here ] You can try this code for a WIN32 console app.

        #include #include using namespace std;

        int main()
        {
        HANDLE hIn;
        HANDLE hOut;
        COORD KeyWhere;
        COORD MouseWhere;
        COORD EndWhere;
        bool Continue = TRUE;
        int KeyEvents = 0;
        int MouseEvents = 0;
        INPUT_RECORD InRec;
        DWORD NumRead;

        hIn = GetStdHandle(STD\_INPUT\_HANDLE);
        hOut = GetStdHandle(STD\_OUTPUT\_HANDLE);
        
        cout << "Key Events   : " << endl;
        cout << "Mouse Events : " << flush;
        
        KeyWhere.X = 15;
        KeyWhere.Y = 0;
        MouseWhere.X = 15;
        MouseWhere.Y = 1;
        EndWhere.X = 0;
        EndWhere.Y = 3;
        
        while (Continue)
        {
            ReadConsoleInput(hIn,
                             &InRec,
                             1,
                             &NumRead);
        
            switch (InRec.EventType)
            {
            case KEY\_EVENT:
                ++KeyEvents;
                SetConsoleCursorPosition(hOut,
                                         KeyWhere);
                cout << KeyEvents << flush;
                if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
                {
                    SetConsoleCursorPosition(hOut,
                                             EndWhere);
                    cout << "Exiting..." << endl;
                    Continue = FALSE;
                }
                break;
        
            case MOUSE\_EVENT:
                ++MouseEvents;
                SetConsoleCursorPosition(hOut,
                                         MouseWhere);
                cout << MouseEvents << flush;
                break;
            }
        }
        
        return 0;
        

        }

        More : [here ]

        M Offline
        M Offline
        myth1990
        wrote on last edited by
        #5

        Is this the header file? I need mouse.h for turbo c++. Thanks for the code.

        S 1 Reply Last reply
        0
        • S Software_Developer

          OS interrupts are only used in 16-bit MSDOS apps. More [here ] You can try this code for a WIN32 console app.

          #include #include using namespace std;

          int main()
          {
          HANDLE hIn;
          HANDLE hOut;
          COORD KeyWhere;
          COORD MouseWhere;
          COORD EndWhere;
          bool Continue = TRUE;
          int KeyEvents = 0;
          int MouseEvents = 0;
          INPUT_RECORD InRec;
          DWORD NumRead;

          hIn = GetStdHandle(STD\_INPUT\_HANDLE);
          hOut = GetStdHandle(STD\_OUTPUT\_HANDLE);
          
          cout << "Key Events   : " << endl;
          cout << "Mouse Events : " << flush;
          
          KeyWhere.X = 15;
          KeyWhere.Y = 0;
          MouseWhere.X = 15;
          MouseWhere.Y = 1;
          EndWhere.X = 0;
          EndWhere.Y = 3;
          
          while (Continue)
          {
              ReadConsoleInput(hIn,
                               &InRec,
                               1,
                               &NumRead);
          
              switch (InRec.EventType)
              {
              case KEY\_EVENT:
                  ++KeyEvents;
                  SetConsoleCursorPosition(hOut,
                                           KeyWhere);
                  cout << KeyEvents << flush;
                  if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
                  {
                      SetConsoleCursorPosition(hOut,
                                               EndWhere);
                      cout << "Exiting..." << endl;
                      Continue = FALSE;
                  }
                  break;
          
              case MOUSE\_EVENT:
                  ++MouseEvents;
                  SetConsoleCursorPosition(hOut,
                                           MouseWhere);
                  cout << MouseEvents << flush;
                  break;
              }
          }
          
          return 0;
          

          }

          More : [here ]

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #6

          I don't think this message was meant for me.

          Veni, vidi, abiit domum

          M 1 Reply Last reply
          0
          • L Lost User

            I don't think this message was meant for me.

            Veni, vidi, abiit domum

            M Offline
            M Offline
            myth1990
            wrote on last edited by
            #7

            Yes, RICHARD it wasn't, it was for SUPERCODER2014. And as u said I posted on author's forum too, I think that might help

            L 1 Reply Last reply
            0
            • M myth1990

              Yes, RICHARD it wasn't, it was for SUPERCODER2014. And as u said I posted on author's forum too, I think that might help

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #8

              And my message was not directed at you, but SuperCoder2014.

              Veni, vidi, abiit domum

              M 1 Reply Last reply
              0
              • L Lost User

                And my message was not directed at you, but SuperCoder2014.

                Veni, vidi, abiit domum

                M Offline
                M Offline
                myth1990
                wrote on last edited by
                #9

                Ohh, sorry my bad, u know that I posted the problem, right? I changed name from number to myth1990. Sorry for misunderstanding

                1 Reply Last reply
                0
                • M myth1990

                  Is this the header file? I need mouse.h for turbo c++. Thanks for the code.

                  S Offline
                  S Offline
                  Software_Developer
                  wrote on last edited by
                  #10

                  Turbo C++ code. Copy paste this to a file named mouse.h . <-------- start of mouse.h

                  include
                  #include
                  #include
                  #include
                  #include

                  const ress=0xb;

                  unsigned hspd,vspd,thv,button,mouse_x,mouse_y;
                  int dirx,diry,dir_x,dir_y,trshold;
                  unsigned char mousestep;

                  void initmouse(void)
                  {
                  asm{
                  mov ax,1h
                  int 33h

                   }
                  

                  }

                  void hidemouse(void)
                  {
                  asm{
                  mov ax,2h
                  int 33h

                   }
                  

                  }

                  void getmousepos(void)
                  {
                  asm{
                  mov ax,3h
                  int 33h
                  mov button,bx
                  mov mouse_x,cx
                  mov mouse_y,dx
                  }
                  }

                  void getmousedirection(void)
                  {
                  asm{
                  mov ax,ress
                  int 33h
                  mov trshold,bx
                  mov dirx,cx
                  mov diry,dx
                  }
                  }

                  void getmousespeed(void)
                  {
                  asm{
                  mov ax,1bh
                  int 33h
                  mov bx,hspd
                  mov cx,vspd
                  mov dx,thv
                  }
                  }

                  <-------- end of mouse.h

                  M 2 Replies Last reply
                  0
                  • S Software_Developer

                    Turbo C++ code. Copy paste this to a file named mouse.h . <-------- start of mouse.h

                    include
                    #include
                    #include
                    #include
                    #include

                    const ress=0xb;

                    unsigned hspd,vspd,thv,button,mouse_x,mouse_y;
                    int dirx,diry,dir_x,dir_y,trshold;
                    unsigned char mousestep;

                    void initmouse(void)
                    {
                    asm{
                    mov ax,1h
                    int 33h

                     }
                    

                    }

                    void hidemouse(void)
                    {
                    asm{
                    mov ax,2h
                    int 33h

                     }
                    

                    }

                    void getmousepos(void)
                    {
                    asm{
                    mov ax,3h
                    int 33h
                    mov button,bx
                    mov mouse_x,cx
                    mov mouse_y,dx
                    }
                    }

                    void getmousedirection(void)
                    {
                    asm{
                    mov ax,ress
                    int 33h
                    mov trshold,bx
                    mov dirx,cx
                    mov diry,dx
                    }
                    }

                    void getmousespeed(void)
                    {
                    asm{
                    mov ax,1bh
                    int 33h
                    mov bx,hspd
                    mov cx,vspd
                    mov dx,thv
                    }
                    }

                    <-------- end of mouse.h

                    M Offline
                    M Offline
                    myth1990
                    wrote on last edited by
                    #11

                    Thanks, I think it works, error relating to mouse.h is gone but not all so I will reply as soon as I debug it.

                    1 Reply Last reply
                    0
                    • S Software_Developer

                      Turbo C++ code. Copy paste this to a file named mouse.h . <-------- start of mouse.h

                      include
                      #include
                      #include
                      #include
                      #include

                      const ress=0xb;

                      unsigned hspd,vspd,thv,button,mouse_x,mouse_y;
                      int dirx,diry,dir_x,dir_y,trshold;
                      unsigned char mousestep;

                      void initmouse(void)
                      {
                      asm{
                      mov ax,1h
                      int 33h

                       }
                      

                      }

                      void hidemouse(void)
                      {
                      asm{
                      mov ax,2h
                      int 33h

                       }
                      

                      }

                      void getmousepos(void)
                      {
                      asm{
                      mov ax,3h
                      int 33h
                      mov button,bx
                      mov mouse_x,cx
                      mov mouse_y,dx
                      }
                      }

                      void getmousedirection(void)
                      {
                      asm{
                      mov ax,ress
                      int 33h
                      mov trshold,bx
                      mov dirx,cx
                      mov diry,dx
                      }
                      }

                      void getmousespeed(void)
                      {
                      asm{
                      mov ax,1bh
                      int 33h
                      mov bx,hspd
                      mov cx,vspd
                      mov dx,thv
                      }
                      }

                      <-------- end of mouse.h

                      M Offline
                      M Offline
                      myth1990
                      wrote on last edited by
                      #12

                      Hi, SuperCoder2014 your codes and links solve the problem about mouse handling during runtime but I stuck at deleting the bar3d(). At some point I have to create bar3d() using and after pressing mouse button I have to make disapper that bar3d() on the same background. Thanks for your help before, and I would appreciate any reply.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups