使用mouse_event来模拟一次选中文本框中的文本(转)
来源:互联网 发布:地暖暖气片空调知乎 编辑:程序博客网 时间:2024/05/22 02:18
使用mouse_event可以模拟一些通过鼠标执行的事情,下面我们就来模拟一次鼠标在EDIT中选择一段文本的过程。
首先我们来分解一下选中文本的鼠标动作,其包括基本方面:
- 将鼠标移动到指定的位置,文本的开始处
- 按下鼠标(WM_LBUTTONDOWN)
- 在按下鼠标的同时移动鼠标到指定的位置
- 松开鼠标左键(WM_LBUTTONUP)
知道了这个过程我们就来通过程序来模拟吧。我自己实验的时候建立了DIALOG工程,在DIALOG上放了一个BUTTON,一个EDIT,将程序写到BUTTON事件中,程序如下:
void CTestChkDlg: nBnClickedButton1()
{
RECT rect;
GetDlgItem(IDC_EDIT)->GetWindowRect(&rect);
SetCursorPos(rect.left+5,rect.top+5);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN,rect.left+1,rect.top+1,0,0);
SetCursorPos(rect.left+60,rect.top+10);
//mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE,500,600,0,0);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTUP,rect.left+60,rect.top+5,0,0);
}
首先我们需要做的是取得EDIT的位置,然后将鼠标移动到那里(SetCursorPos),这里加5是让鼠标在EDIT里面,因为EDIT有边,如果按照RECT的值来可能选择不了;然后使用MOUSEEVENTF_LEFTDOWN来按下鼠标,在按下鼠标的时候再将鼠标移动到文本的指定位置,然后松开鼠标。好了文本选中了。
鼠标模拟函数:
VOID mouse_event( DWORD dwFlags, // flags specifying various motion/click variants DWORD dx, // horizontal mouse position or position change DWORD dy, // vertical mouse position or position change DWORD dwData, // amount of wheel movement DWORD dwExtraInfo // 32 bits of application-defined information);
Parameters
- dwFlags
- A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values:
Value Meaning MOUSEEVENTF_ABSOLUTE指定鼠标绝对坐标MOUSEEVENTF_MOVESpecifies that movement occurred.MOUSEEVENTF_LEFTDOWNSpecifies that the left button is down.MOUSEEVENTF_LEFTUPSpecifies that the left button is up.MOUSEEVENTF_RIGHTDOWNSpecifies that the right button is down.MOUSEEVENTF_RIGHTUPSpecifies that the right button is up.MOUSEEVENTF_MIDDLEDOWNSpecifies that the middle button is down.MOUSEEVENTF_MIDDLEUPSpecifies that the middle button is up.MOUSEEVENTF_WHEELWindows NT: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData
键盘模拟函数
VOID keybd_event( BYTE bVk, // virtual-key code BYTE bScan, // hardware scan code DWORD dwFlags, // flags specifying various function options DWORD dwExtraInfo // additional data associated with keystroke);
Parameters
- bVk
- Specifies a virtual-key code. The code must be a value in the range 1 to 254.
- bScan
- Specifies a hardware scan code for the key.
- dwFlags
- A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags.
Value Meaning KEYEVENTF_EXTENDEDKEYIf specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).KEYEVENTF_KEYUPIf specified, the key is being released. If not specified, the key is being depressed.
- 使用mouse_event来模拟一次选中文本框中的文本
- 使用mouse_event来模拟一次选中文本框中的文本
- 使用mouse_event来模拟一次选中文本框中的文本
- 使用mouse_event来模拟一次选中文本框中的文本
- 使用mouse_event来模拟一次选中文本框中的文本(转)
- 用Mouse_event()来模拟鼠标操作
- 用Mouse_event()来模拟鼠标操作
- mouse_event 鼠标模拟(转集)
- 使用WH_MOUSE_LL钩子来判断按键是否是mouse_event模拟的
- 前端开发使用css禁止选中文本,模拟双击禁止选中文本,网页禁止选中文本
- 用Mouse_event和Keybd_event来模拟鼠标和键盘
- 用Mouse_event()来控制鼠标操作
- 用Mouse_event()来控制鼠标操作
- 用Mouse_event()来控制鼠标操作
- 用Mouse_event()来控制鼠标操作
- mouse_event(模拟鼠标)和keybd_event(模拟键盘)
- keybd_event,mouse_event 模拟产生键盘事件、鼠标事件的使用
- 使用API函数mouse_event可以模拟鼠标事件
- 提升权限获取其他系统进程的路径(转)
- VC++开发BHO插件(引用)
- ShellExecute的各种妙用(引)
- ADO数据库详细操作(引)
- CString 及char 指针和数组的问题(转)
- 使用mouse_event来模拟一次选中文本框中的文本(转)
- FAT32引导扇区代码
- 主引导扇区代码(MBR)
- c#常用函数
- 數字證書的操作(轉載)
- XML文档简单读写方法
- SQL删除逻辑重复记录的最简方法
- 删除表中的重复记录
- 调用MSN发消息