473,544 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cursor Position

Hi all,

I am making a DirectInput application wich must report correctly the
cursor position in windowed mode (it means it has to be the same as
Microsoft Window´s cursor position).
First of all, I get Windows System Mouse Speed by using the function :
SystemParameter sInfo(SPI_GETMO USESPEED, 0, &m_nMouseSpeed, 0);
After I am reading the last Windows cursor position with GetCursorPos.
Then I read all mouse buffered data using GetDeviceData (from a
IDirectInputDev ice8 interface), and when the field dwOfs from structure
DIDEVICEOBJECTD ATA has value DIFMODS_X or DIFMODS_Y I sum the value from the
field dwData multiplied by the the value m_nMouseSpeed. After all buffered
data was read, the next GetCursorPos and my estimated position are
different.
Can anyone point me to the correct procedure in order from both, my
estimated cursor position and GetCursorPos meet?

Thank you all.
Paul.

For instance, my procedure is this:

class CInputMan
{
public:
CInputMan(CKern el* poKernel,const HWND hWnd=NULL);
virtual ~CInputMan();

static CInputMan*& GetInputMan();

const bool Update();

const unsigned int GetKeyboardSize ();
const bool GetCurrentKeybo ardState(unsign ed char* pachKeyboardSta te);
const bool GetLastKeyboard State(unsigned char* pachKeyboardSta te);

const bool GetCurrentMouse State(float& fMouseX, float& fMouseY,unsigne d
int& nWheelPosition, unsigned long& nMouseButtonSta te);
const bool GetLastMouseSta te(float& fMouseX, float& fMouseY,unsigne d
int& nWheelPosition, unsigned long& nMouseButtonSta te);
protected:
class CMouseState
{
public:
CMouseState():m _nX(0),m_nY(0), m_nMouseButtons (0){}
virtual ~CMouseState(){ };

void GetMouseState(i nt& nX,int& nY,int& nWheelPosition, unsigned
long& nMouseButtons)
{
nX=m_nX;
nY=m_nY;
nMouseButtons=m _nMouseButtons;
nWheelPosition= m_nWheelPositio n;
}

void SetMouseState(c onst int nX,const int nY,const int
nWheelPosition, const unsigned long nMouseButtons)
{
m_nX=nX;
m_nY=nY;
m_nMouseButtons =nMouseButtons;
m_nWheelPositio n=nWheelPositio n;
}

int& GetMouseX()
{
return m_nX;
}

int& GetMouseY()
{
return m_nY;
}

int& GetWheelPositio n()
{
return m_nWheelPositio n;
}

unsigned long& GetButtons()
{
return m_nMouseButtons ;
}
protected:
int m_nX;
int m_nY;
int m_nWheelPositio n;
unsigned long m_nMouseButtons ;
};

typedef vector<CMouseSt ate> TDDeviceStateCo ntainer;
typedef TDDeviceStateCo ntainer::iterat or
TDDeviceStateCo ntainerIterator ;

const bool Init();
const bool InitKeyboard();
const bool InitMouse();

const bool UpdateKeyboardS tate();
const bool UpdateMouseStat e();

static IDirectInput8*& GetDirectInputI nterface();

IDirectInputDev ice8* m_piSystemKeybo ardDevice;
IDirectInputDev ice8* m_piSystemMouse Device;

HWND m_hApplicationW indow;
CKernel *m_poKernel;
static const unsigned int m_cnStandardBuf ferSize=16;
static const unsigned int m_cnStandardKey boardSize=256;

unsigned char
m_auchCurrentKe yboardState[m_cnStandardKey boardSize];
unsigned char
m_auchLastKeybo ardState[m_cnStandardKey boardSize];

int m_nMouseSpeed;
int m_nMouseWheelSp eed;

CMouseState m_oCurrentMouse State;
CMouseState m_oLastMouseSta te;

TDDeviceStateCo ntainer m_cMouseStateCo ntainer;
};

const bool CInputMan::Init Mouse()
{
IDirectInput8*&
piDirectInputIn terface=GetDire ctInputInterfac e();
HRESULT hResult(DI_OK);
DIPROPDWORD dipdw;

hResult = piDirectInputIn terface->CreateDevice(G UID_SysMouse,
&m_piSystemMous eDevice, NULL);
if (hResult!=DI_OK )
{
return false;
}

hResult = m_piSystemMouse Device->SetDataFormat( &c_dfDIMouse );
if (hResult!=DI_OK )
{
return false;
}

hResult =
m_piSystemMouse Device->SetCooperative Level(m_hApplic ationWindow,DIS CL_NONEXC
LUSIVE| DISCL_FOREGROUN D);
if (hResult!=DI_OK )
{
return false;
}

// the header
dipdw.diph.dwSi ze = sizeof(DIPROPDW ORD);
dipdw.diph.dwHe aderSize = sizeof(DIPROPHE ADER);
dipdw.diph.dwOb j = 0;
dipdw.diph.dwHo w = DIPH_DEVICE;
// the data
dipdw.dwData = m_cnStandardBuf ferSize;

hResult = m_piSystemMouse Device->SetProperty(DI PROP_BUFFERSIZE ,
&dipdw.diph) ;
if (hResult!=DI_OK )
{
return false;
}

return true;
}
const bool CInputMan::Upda teMouseState()
{
DIDEVICEOBJECTD ATA stMouseState;
DWORD dwElementsRead( 1);
HRESULT hResult(DI_OK);
DWORD dwSequenceNumbe r(-1);
unsigned int nCount(0);
unsigned long nMouseButtons(0 );
unsigned long nBitMask(1);
unsigned int nBitOffset(0);
CMouseState oMouseState(m_o CurrentMouseSta te);
int nMouseX(oMouseS tate.GetMouseX( ));
int nMouseY(oMouseS tate.GetMouseY( ));
int nMouseWheel(oMo useState.GetWhe elPosition());
POINT stPoint;

do
{
hResult =
m_piSystemMouse Device->GetDeviceData( sizeof(DIDEVICE OBJECTDATA),&st MouseStat
e, &dwElementsRead ,0);
if ((hResult==DIER R_INPUTLOST)||( hResult==DIERR_ NOTACQUIRED))
{
hResult = m_piSystemMouse Device->Acquire();
if (hResult!=DI_OK )
{
return false;
}
hResult =
m_piSystemMouse Device->GetDeviceData( sizeof(DIDEVICE OBJECTDATA),&st MouseStat
e, &dwElementsRead ,0);
if (hResult!=DI_OK )
{
return false;
}
}
else if (hResult!=DI_OK )
{
return false;
}

switch (stMouseState.d wOfs)
{
case DIMOFS_X:
nMouseX+=stMous eState.dwData*m _nMouseSpeed;
break;
case DIMOFS_Y:
nMouseY+=stMous eState.dwData*m _nMouseSpeed;
break;
case DIMOFS_Z:
nMouseWheel+=st MouseState.dwDa ta*m_nMouseWhee lSpeed;
break;
}

nBitOffset=0;
for (nCount=DIMOFS_ BUTTON0;nCount< =DIMOFS_BUTTON7 ;nCount++,nBitO ffset++)
{
if (stMouseState.d wOfs==nCount)
{
if (stMouseState.d wData&0x80)
{
nMouseButtons|= nBitMask<<nBitO ffset;
}
else
{
nMouseButtons&= ~(nBitMask<<nBi tOffset);
}
}
}

if (stMouseState.d wSequence==dwSe quenceNumber)
{
oMouseState.Get Buttons()|=nMou seButtons;
oMouseState.Get MouseX()=nMouse X;
oMouseState.Get MouseY()=nMouse Y;
oMouseState.Get WheelPosition() =nMouseWheel;

if (m_cMouseStateC ontainer.empty( ))
{
m_cMouseStateCo ntainer.push_ba ck(oMouseState) ;
}
else
{
m_cMouseStateCo ntainer.back()= oMouseState;
}
}
else
{
oMouseState.Get Buttons()=nMous eButtons;
oMouseState.Get MouseX()=nMouse X;
oMouseState.Get MouseY()=nMouse Y;
oMouseState.Get WheelPosition() =nMouseWheel;
m_cMouseStateCo ntainer.push_ba ck(oMouseState) ;
}
}
while (dwElementsRead >0);

GetCursorPos(&s tPoint);
ScreenToClient( m_hApplicationW indow,&stPoint) ;
oMouseState.Get MouseX()=stPoin t.x;
oMouseState.Get MouseY()=stPoin t.y;

m_oLastMouseSta te=m_oCurrentMo useState;
m_oCurrentMouse State=oMouseSta te;

return true;
}
Nov 17 '05 #1
1 2372
Hi Paul,
Can I please have the working code of your cursor position program. I
am trying to simulate the mouse like a digitizer pen.
I need to save mouse co-ordinates when a user moves the mouse FAST
inside a window (like a jerky movement). The coordinates will be saved
into a notepad file with 'exact time' (millisecond precision) for each
co-ordinate. A normal mouse has a sampling rate of less than 200 Hz.
So, if a mouse moves for 1 sec, it sends about 200 coordinates to the
system. I am expecting a notepad file in the following form:

Time (s) X Y
0.000 156 86
0.005 156 89
0.010 157 90
.... ... ...

I am trying to use the "DIDEVICEOBJECT DATA Structure" to get the mouse
cursor positoin and also the time stamp. A sample working code from you
can be a great help for me.

Regards,
Aziz

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4890
by: PeP | last post by:
Good morning, I have a form containing a text-area, I'd like to know if it exists a function that, when I activate an event, returns the position of the cursor in the text-area. For example, I write ten words in the text-area, then I move the cursor at the beginning of the second word and activate the event (for example, click on a...
1
13152
by: Dan H. | last post by:
Hello, I want to try to retrieve the cursor position x and y relative to the form the cursor is over. The way I am doing it now is: 1. Retrieve the left and top position of the form relative to the desktop 2. Retrieve the desktop cursor position. 3. Take the difference of the forms left and top position. Adjust the desktop cursor...
1
5073
by: Tantra Veda | last post by:
Hello C# gurus, I have a question about finding cursor position in NumericUpDown control. On my form I have a numericUpDown control with 2 decimal places. I want to increment value in the numeric box by 1 if my cursor is in front of the decimal point. If the cursor is after the decimal point, I want to increment the value by 0.1. How do I...
1
3831
by: objectref | last post by:
Hi to all, we have the MousePosition property that we can get the Point of the position of the mouse cursor on the screen, but is it there a way to get the respective Point of a cursor in a TextBox ?? (relative to screen) I mean, i have a textbox that i write some text and i want to know the exact point location of the cursor at any...
22
4486
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't that difficult, but to find the next line is more difficult. For exemple: if my cursor is on line 200, it has to start searching on line 201, and...
2
5768
by: tony | last post by:
Hello! Assume I catch a double click in a form by using the event handler that forms designer create for me. Now to my question when I double click in the form the event handler is trigged but when I'm in this event handler I want to find out the cursor position(x,y cordinates) where the double click occurred how is that done? //Tony
1
11947
by: jobs | last post by:
I'm trying to understand this and don't get it... I found some code that looks like it's going to work if I can make sense of how to position the div. The code displays a div with some data when I mouse over an element (A column in an ASP.NET Gridview, but I suppose that's not important) Everything works great, except I can't seem to...
4
4665
by: Billy | last post by:
Hi all, I'm building a text file from a database table using the ASP Write Method and would like to position the cursor in a specific column position before writing the fields. As I loop through and write the fields into strings of rows, I want to be able to put field1 in row1/column position1, field2 in row1/column position10,.....etc. ...
4
6953
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I just gotta fix it. I need to make some calculations on the measurements and VB6 is my language. Yes, the system mouse will corrupt the...
0
7413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7597
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7752
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5894
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4902
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
980
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
650
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.