Handling mouse using OS interrupts
-
Hi, I'm noob in programming language and I need to make some project using it. So I tried to make a game called 'Baghchal'/Tiger and Goat/Moving Tiger, but its too complex for me so I copied Sir Srinivas Varukala's code. When I run compile the program it shows error about 'cannot include mouse.h file'. I would be glad to receive any kind of idea or help. Here is the source code Tiger Goat Console Based Game - using C++[^]
-
Hi, I'm noob in programming language and I need to make some project using it. So I tried to make a game called 'Baghchal'/Tiger and Goat/Moving Tiger, but its too complex for me so I copied Sir Srinivas Varukala's code. When I run compile the program it shows error about 'cannot include mouse.h file'. I would be glad to receive any kind of idea or help. Here is the source code Tiger Goat Console Based Game - using C++[^]
-
You should post your question in the forum at the end of the article so the author gets notified.
Veni, vidi, abiit domum
-
You should post your question in the forum at the end of the article so the author gets notified.
Veni, vidi, abiit domum
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 ]
-
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 ]
-
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 ]
-
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
-
Turbo C++ code. Copy paste this to a file named mouse.h . <-------- start of mouse.h
include
#include
#include
#include
#includeconst 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
-
Turbo C++ code. Copy paste this to a file named mouse.h . <-------- start of mouse.h
include
#include
#include
#include
#includeconst 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
-
Turbo C++ code. Copy paste this to a file named mouse.h . <-------- start of mouse.h
include
#include
#include
#include
#includeconst 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
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.