Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mouse movements


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Vanz   Members   -  Reputation: 204

Like
0Likes
Like

Posted 05 March 2013 - 11:15 AM

Hi, what are the commands to make the mouse cursor move and to make it click... basically I want to make a mouse curse mirror my movements from one computer to a second computer I am networked with, I want to be able to move then click and execute an icon on the 2nd machine...

 

Thanks,

 

rh

 



Sponsor:

#2 viper110110   Members   -  Reputation: 576

Like
0Likes
Like

Posted 05 March 2013 - 11:56 AM

I think you can use GetCursorPos and SetCursorPos on windows to get and set the positions. Not sure about the button presses, I use XInput for mine and you probably don't want to do that.



#3 Banderi   Members   -  Reputation: 135

Like
0Likes
Like

Posted 05 March 2013 - 01:52 PM

If you want to just check the press of its buttons, you can use GetKeyState on the button keys:

 

if ((GetKeyState(VK_LBUTTON) & 0x80) != 0)
{
   // left button pressed, do something
}
if ((GetKeyState(VK_RBUTTON) & 0x80) != 0)
{
   // right button pressed, do something
}


#4 Vanz   Members   -  Reputation: 204

Like
0Likes
Like

Posted 05 March 2013 - 07:29 PM

If you want to just check the press of its buttons, you can use GetKeyState on the button keys:

 



if ((GetKeyState(VK_LBUTTON) & 0x80) != 0)
{
   // left button pressed, do something
}
if ((GetKeyState(VK_RBUTTON) & 0x80) != 0)
{
   // right button pressed, do something
}

No I can read the mouse fine, I need to move a mouse on a second computer now, and make it simulate an actual mouse button click...

 

I'll try SetCursorPos Viper for moving the cursor...



#5 Vortez   Crossbones+   -  Reputation: 2688

Like
0Likes
Like

Posted 05 March 2013 - 08:24 PM

You really want to use the SendInput() api for this, and you can also simulate a keyboard with it too. It's a bit hard to get the hang of it at first, but it's not too bad once you got the idea. What's cool about SendInput() is that it's like having a second mouse or keyboard instead of overwritting the one you have.

 

Here's some (obsolete) code from my RemotePC project, take what you need from it

 

void CSomeClass::ProcessInputMsg(DWORD MsgType, DWORD DataLen, DWORD *lParam){	// Init the INPUT structure	INPUT Input;	ZeroMemory(&Input, sizeof(Input));	switch(MsgType)	{	case MSG_MOUSE_INPUT:		// Create and init a stucture to read our recved buffer		MousePacketDataStruct MouseDat;		memcpy(&MouseDat, pBuffer, DataLen);		// Calculate the mouse cursor position		Input.type = INPUT_MOUSE;		if(MouseDat.Msg != WM_MOUSEWHEEL){			Input.mi.dx = (WORD)(MouseDat.xPos * 0xFFFF);			Input.mi.dy = (WORD)(MouseDat.yPos * 0xFFFF);					DWORD x = (DWORD)(MouseDat.xPos * GetSystemMetrics(SM_CXSCREEN));			DWORD y = (DWORD)(MouseDat.yPos * GetSystemMetrics(SM_CYSCREEN));			*lParam = x | (y << 15);			// We're gonna use Absolute value (0..65535)			Input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;			// Select the action to simulate			switch(MouseDat.Msg)			{			case WM_MOUSEMOVE  : Input.mi.dwFlags |= MOUSEEVENTF_MOVE;                            break;			case WM_LBUTTONDOWN: Input.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;   *lParam |= (2 << 29); break;			case WM_LBUTTONUP  : Input.mi.dwFlags |= MOUSEEVENTF_LEFTUP;     *lParam |= (3 << 29); break;			case WM_MBUTTONDOWN: Input.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN; *lParam |= (4 << 29); break;			case WM_MBUTTONUP  : Input.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;   *lParam |= (5 << 29); break;			case WM_RBUTTONDOWN: Input.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;  *lParam |= (6 << 29); break;			case WM_RBUTTONUP  : Input.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;    *lParam |= (7 << 29); break;				}		} else {			Input.mi.dx = 0;			Input.mi.dy = 0;			Input.mi.dwFlags = MOUSEEVENTF_WHEEL;					DWORD x = (DWORD)(MouseDat.xPos * GetSystemMetrics(SM_CXSCREEN));			DWORD y = (DWORD)(MouseDat.yPos * GetSystemMetrics(SM_CYSCREEN));			*lParam = MouseDat.NumRoll | (1 << 29);		}		break;	case MSG_KEYBOARD_INPUT:			// Create and init a stucture to read our recved buffer		KeyboardPacketDataStruct KbDat;		memcpy(&KbDat, pBuffer, DataLen);		// Fill our structure with the given key data		Input.type = INPUT_KEYBOARD;		switch(KbDat.Msg)		{		case WM_KEYDOWN: Input.ki.dwFlags = 0;               break;		case WM_KEYUP  : Input.ki.dwFlags = KEYEVENTF_KEYUP; break;		}		if(KbDat.IsExtended)			Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;		Input.ki.wVk   = KbDat.vkCode;		Input.ki.wScan = KbDat.ScanCode;						//		*lParam = Input.ki.wVk | (Input.ki.wScan << 16) | (KbDat.Msg == WM_KEYUP ? 1 << 24 : 0);		break;	}	// Simulate the mouse/keyboard	SendInput(1, &Input, sizeof(Input));}

 

I said obsolete because i later commented this code and processed input by batch, instead of 1 message at the time,  to limit bandwith waste, still it's easier to start this way. This code is just to give you an idea, it wont compile since it's just a piece of the whole program. Just look how i fill out the Input structure.


Edited by jbadams, 04 April 2013 - 05:55 AM.
Restored post contents from history.


#6 Vanz   Members   -  Reputation: 204

Like
0Likes
Like

Posted 06 March 2013 - 12:15 PM

wow, thanks Vortez... that could be the ticket...



#7 Vortez   Crossbones+   -  Reputation: 2688

Like
0Likes
Like

Posted 06 March 2013 - 12:48 PM

It is, my program work just fine, i use it to remote control my mother computer when she need help lol

 

Although i have to say, this is one of my most complex project i've ever made, since it's multithreaded and all...


Edited by Vortez, 06 March 2013 - 12:49 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS