Total members 11894 |It is currently Sun Nov 24, 2024 1:23 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This C/C++ show the position of mouse (X,Y) at the screen :
cpp code
#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
HANDLE hIn;
HANDLE hOut;
COORD MouseWhere = {30, 20};
COORD DClickWhere = {30, 20};





bool Continue = TRUE;
DWORD EventCount;
int LoopCount = 0;
int KeyEvents = 0;
INPUT_RECORD InRec;
DWORD NumRead;

hIn = GetStdHandle(STD_INPUT_HANDLE);
hOut = GetStdHandle(STD_OUTPUT_HANDLE);

cout << "Mouse is at : " << endl;
cout << "Double Click at : " << endl;




while (Continue)
{



Sleep(10); // To slow it down!!

GetNumberOfConsoleInputEvents(hIn,&EventCount);
while (EventCount > 0)
{
ReadConsoleInput(hIn,&InRec,1,&NumRead);

if (InRec.EventType == KEY_EVENT)
{
if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
{


cout << "Exiting..." << endl;
Continue = FALSE;
}
}
else if (InRec.EventType == MOUSE_EVENT)
{

if (InRec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED)
{
SetConsoleCursorPosition(hOut,
MouseWhere);
cout << InRec.Event.MouseEvent.dwMousePosition.X << "," <<
InRec.Event.MouseEvent.dwMousePosition.Y << " " << flush;
}
else if (InRec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK)
{
SetConsoleCursorPosition(hOut,
DClickWhere);
cout << InRec.Event.MouseEvent.dwMousePosition.X << "," <<
InRec.Event.MouseEvent.dwMousePosition.Y << " " << flush;
}
}

GetNumberOfConsoleInputEvents(hIn,&EventCount);
}
}

return 0;
}


I hope it is helpfull



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Thank you so much!!! It is highly useful for my project. CHEERS!!


Author:
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Mouse position in C++
 Get Mouse Position using JQuery     -  
 Change background position when mouse over     -  
 X and Y background position     -  
 ORACLE/ SQL DBA this is a CTH position. No H1B’s     -  
 static vs fixed div position     -  
 setting div background position     -  
 right bottom background image position     -  
 Set position of background image in pixels     -  
 Get the position of HTML element using JQuery     -  
 Slide automatically-specific speed to a determined position     -  



Topic Tags

C++ Inputs
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com