2 registered members (AndrewAMD, dr_panther),
730
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
mouse
#290465
09/19/09 10:15
09/19/09 10:15
|
Joined: Jul 2007
Posts: 959 nl
flits
OP
User
|
OP
User
Joined: Jul 2007
Posts: 959
nl
|
is it possible to simulate a mouse click
like when you press space the windows mouse is clicked
thx flits
"empty"
|
|
|
Re: mouse
[Re: flits]
#290471
09/19/09 11:07
09/19/09 11:07
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
The Win32 function "SendInput" is what you want... Here is how to simulate a left-click...
void LeftClick()
{
INPUT Input={0};
// left down
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1,&Input,sizeof(INPUT));
}
So then just call LeftClick() and a left-click will be simulated. This only allows you to click on the current mouse position. If you want to first move the mouse use this function...
void MouseMove(int x, int y )
{
double fScreenWidth = ::GetSystemMetrics( SM_CXSCREEN )-1;
double fScreenHeight = ::GetSystemMetrics( SM_CYSCREEN )-1;
double fx = x*(65535.0f/fScreenWidth);
double fy = y*(65535.0f/fScreenHeight);
INPUT Input={0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = fx;
Input.mi.dy = fy;
SendInput(1,&Input,sizeof(INPUT));
}
Last edited by DJBMASTER; 09/20/09 07:43.
|
|
|
Re: mouse
[Re: DJBMASTER]
#290490
09/19/09 13:42
09/19/09 13:42
|
Joined: Jul 2007
Posts: 959 nl
flits
OP
User
|
OP
User
Joined: Jul 2007
Posts: 959
nl
|
thx but dont get it to work do i need to include some header ore structs
i am not so good with the win32 comments but including windows.h didnt work
Last edited by flits; 09/19/09 13:43.
"empty"
|
|
|
Re: mouse
[Re: flits]
#290575
09/20/09 07:40
09/20/09 07:40
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Hi, sorry for the late reply. I assumed you knew about the structs. This should work now...
#include <windows.h>
#define MOUSE_INPUT 0x0000
#define MOUSEEVENTF_LEFTDOWN 0x0002
typedef struct
{
long dx;
long dy;
DWORD mouseData;
DWORD dwFlags;
DWORD time;
long dwExtraInfo;
}
MOUSEINPUT;
typedef struct
{
DWORD type;
MOUSEINPUT mi;
}
INPUT;
int WINAPI SendInput(int nInputs,INPUT* pInputs,int cbSize);
#define PRAGMA_API SendInput;user32!SendInput
//////////////////////////////////////////////////////////////
void LeftClick()
{
INPUT Input;
Input.type = MOUSE_INPUT;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1,&Input,sizeof(INPUT));
}
I havent included the function to move the mouse, because you can do that by changing mouse_pos/pos_cursor.
Last edited by DJBMASTER; 09/20/09 07:41.
|
|
|
Re: mouse
[Re: DJBMASTER]
#290591
09/20/09 10:07
09/20/09 10:07
|
Joined: Jul 2007
Posts: 959 nl
flits
OP
User
|
OP
User
Joined: Jul 2007
Posts: 959
nl
|
i did know there needed to be some struct but it is always hard to find them on the msdn page
it realy works good
thx flits
"empty"
|
|
|
Re: mouse
[Re: DJBMASTER]
#291319
09/24/09 14:48
09/24/09 14:48
|
Joined: Jul 2007
Posts: 959 nl
flits
OP
User
|
OP
User
Joined: Jul 2007
Posts: 959
nl
|
oke next problem is the key mapping i just want to do somthin like presing awds and more but i gues if i can press one button i can do the rest this is what i got for now
#define KEYEVENTF_UNICODE 0x0004
#define KEYEVENTF_SCANCODE 0x0008
#define INPUT_KEYBOARD 0x0001
typedef struct{
WORD wVk;
WORD wScan;
DWORD dwFlags;
DWORD time;
long dwExtraInfo;
}KEYBDINPUT;
typedef struct
{
DWORD type;
KEYBDINPUT ki;
}
KEYINPUT;
"empty"
|
|
|
Re: mouse
[Re: flits]
#291440
09/25/09 10:14
09/25/09 10:14
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
hmm, should be the same as the mouse i would think...
#define INPUT_KEYBOARD 0x0001
#define KEYEVENTF_SCANCODE 0x0008
typedef struct
{
WORD wVk;
WORD wScan;
DWORD dwFlags;
DWORD time;
long dwExtraInfo;
}
KEYBDINPUT;
typedef struct
{
DWORD type;
KEYBDINPUT ki;
}
INPUT;
int WINAPI SendInput(int nInputs,INPUT* pInputs,int cbSize);
#define PRAGMA_API SendInput;user32!SendInput
///////////////////////////////////////////////////////////////////////
void PressKey (int scan_code)
{
INPUT Input;
Input.type = INPUT_KEYBOARD;
Input.ki.wScan = scan_code;
Input.ki.dwFlags = KEYEVENTF_SCANCODE;
SendInput(1,&Input,sizeof(Input));
}
I don't have time to test this right now, but it looks ok.
|
|
|
Re: mouse
[Re: DJBMASTER]
#291645
09/27/09 08:17
09/27/09 08:17
|
Joined: Jul 2007
Posts: 959 nl
flits
OP
User
|
OP
User
Joined: Jul 2007
Posts: 959
nl
|
hmmm i tried allot but i cant get it to work
"empty"
|
|
|
|