如何实现鼠标单击

王楚铁 2009-07-10 10:48:38
菜鸟求救::

鼠标就放在制定的位置。每30秒想单击一下,在MFC里该如何实现啊 ?

定时器我会用。但是鼠标单击的函数还不会用,请大侠们详细讲解一下,谢谢。请给出源代码。



另:如何让鼠标在制定的坐标上点击,比如在屏幕左上角点一下后,再去右上角点。。
...全文
167 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
coohai 2009-07-10
  • 打赏
  • 举报
回复
SendInput
The SendInput function synthesizes keystrokes, mouse motions, and button clicks.

UINT SendInput(
UINT nInputs, // count of input events
LPINPUT pInputs, // array of input events
int cbSize // size of structure
);
Parameters
nInputs
[in] Specifies the number of structures in the pInputs array.
pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail.
Return Values
The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread.

To get extended error information, call GetLastError.

Remarks
The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events aren't interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput.

This function does not reset the keyboard's current state. Any keys that are already pressed when the function is called might interfere with the events that this function generates. To avoid this problem, check the keyboard's state with the GetAsyncKeyState function and correct as necessary.

Requirements
Windows NT/2000: Requires Windows NT 4.0 SP3 or later.
Windows 95/98: Requires Windows 98.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.

INPUT
The INPUT structure is used by SendInput to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks.

typedef struct tagINPUT {
DWORD type;
union {
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
} INPUT, *PINPUT;
Members
type
Specifies the type of the input event. This member can be one of the following values. Value Meaning
INPUT_MOUSE The event is a mouse event. Use the mi structure of the union.
INPUT_KEYBOARD The event is a keyboard event. Use the ki structure of the union.
INPUT_HARDWARE Windows 95/98: The event is from input hardware other than a keyboard or mouse. Use the hi structure of the union.


mi
A MOUSEINPUT structure that contains information about a simulated mouse event.
ki
A KEYBDINPUT structure that contains information about a simulated keyboard event.
hi
Windows 95/98: A HARDWAREINPUT structure that contains information about a simulated event from input hardware other than a keyboard or mouse.
Remarks
This structure contains information identical to that used in the parameter list of the keybd_event or mouse_event function.

Windows 2000: INPUT_KEYBOARD supports nonkeyboard input methods, such as handwriting recognition or voice recognition, as if it were text input by using the KEYEVENTF_UNICODE flag. For more information, see the remarks section of KEYBDINPUT.

Requirements
Windows NT/2000: Requires Windows NT 4.0 SP3 or later.
Windows 95/98: Requires Windows 98.
Header: Declared in Winuser.h; include Windows.h.

以下来自MSDN。
调用SendInput就可以。鼠标先按下、再释放就是click。
shuyisheng 2009-07-10
  • 打赏
  • 举报
回复
定时器到了,调用那个CLICKED函数,行么?
eatmyball 2009-07-10
  • 打赏
  • 举报
回复
这大概是按键精灵的作用··有函数能主动实现?
饿··求解~
fengrx 2009-07-10
  • 打赏
  • 举报
回复
::SendMessage(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,lParam);

hwnd是窗口句柄,lParam是鼠标位置。

xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
jiabin_007 2009-07-10
  • 打赏
  • 举报
回复
在定时器函数中SendMessage触犯鼠标事件

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧