比如,在程序里发一个's'的按键消息,使windows(而不是程序本身进程)能接收都这个消息,如果这时候是Word在激活状态,那么Word里就打出一个s。就好像windows屏幕键盘(开始-程序-附件-辅助工具-屏幕键盘)那样。鼠标也一样,比如我要让鼠标停在某处,并不停单击左键。谁知道如何做?
这样的程序很有用,可以实现一些手工工作的自动化。我之所以想写这个程序,是因为我经常要在PhotoShop里转换大批大批的图像格式,先打开几百张jpg图片,一张一张另存为tif图片,整个过程都是几个alt+f,a,tab,t,i,f,enter这样的按键重复。所以我想写个程序在程序中发出这些按键的消息,而photoshop接收到,这样,机器在运行,我就可以先睡觉了。希望得到大家帮助!
谢谢!
这样的程序很有用,可以实现一些手工工作的自动化。我之所以想写这个程序,是因为我经常要在PhotoShop里转换大批大批的图像格式,先打开几百张jpg图片,一张一张另存为tif图片,整个过程都是几个alt+f,a,tab,t,i,f,enter这样的按键重复。所以我想写个程序在程序中发出这些按键的消息,而photoshop接收到,这样,机器在运行,我就可以先睡觉了。希望得到大家帮助!
谢谢!
解决方案 »
- 隐蔽窗口的作用是什么?
- 重叠端口的问题
- IHTMLAnchorElement中的get_href()是得到url,该如何得到url对应的链接文字呢?
- ex combobox的FindString的小问题
- 怎么得到机器的 IP,subnet mask?
- 已知内码,怎样显示汉字?
- 200分求救!关于打印对齐,我百思不得其解!
- 已经有采集到的声音的缓冲区。怎么得到它的强度?
- 如何在formview中叠入(删除)formview?
- 菜鸟问题,为何对话框所加的菜单资源中,pCmdUI->SetCheck(1)无效?该怎么办?
- 十万火急,关于屏幕抓图!
- 如何在一个程序中把CView类型的视图变为CFormView?
你可以先用EnumWindows或者Findwindow找到photoshop的窗口句柄,然后用SendMessage向这个窗全发送WM_KEYDOWN和WM_KEYUP消息
还有要是在photoshop里弹出一个“另存为”对话框,那这样的对话框是算一个窗体还是算photoshop的?
mouse_event模拟系统按键/鼠标
The mouse_event function synthesizes mouse motion and button clicks. Windows NT/2000/XP: This function has been superseded. Use SendInput instead.VOID mouse_event(
DWORD dwFlags, // motion and click options
DWORD dx, // horizontal position or change
DWORD dy, // vertical position or change
DWORD dwData, // wheel movement
ULONG_PTR dwExtraInfo // application-defined information
);
Parameters
dwFlags
[in] Specifies various aspects of mouse motion and button clicking. This parameter can be certain combinations of the following values. Value Meaning
MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Res section.
MOUSEEVENTF_MOVE Specifies that movement occurred.
MOUSEEVENTF_LEFTDOWN Specifies that the left button is down.
MOUSEEVENTF_LEFTUP Specifies that the left button is up.
MOUSEEVENTF_RIGHTDOWN Specifies that the right button is down.
MOUSEEVENTF_RIGHTUP Specifies that the right button is up.
MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button is down.
MOUSEEVENTF_MIDDLEUP Specifies that the middle button is up.
MOUSEEVENTF_WHEEL Windows NT/2000/XP: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is specified in dwData
MOUSEEVENTF_XDOWN Windows 2000/XP: Specifies that an X button was pressed.
MOUSEEVENTF_XUP Windows 2000/XP: Specifies that an X button was released.
The values that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released. You cannot specify both MOUSEEVENTF_WHEEL and either MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP simultaneously in the dwFlags parameter, because they both require use of the dwData field. dx
[in] Specifies the mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the mouse's actual x-coordinate; relative data is specified as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.
dy
[in] Specifies the mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the mouse's actual y-coordinate; relative data is specified as the number of mickeys moved.
dwData
[in] If dwFlags contains MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
Windows 2000/XP: If dwFlags contains MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP, then dwData specifies which X buttons were pressed or released. This value may be any combination of the following flags. Value Meaning
XBUTTON1 Set if the first X button was pressed or released.
XBUTTON2 Set if the second X button was pressed or released. If dwFlags is not MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or MOUSEEVENTF_XUP, then dwData should be zero. dwExtraInfo
[in] Specifies an additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.
Return Values
This function has no return value.
If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is specified as absolute or relative integer values. If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner. If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up). Relative mouse motion is subject to the settings for mouse speed and acceleration level. An end user sets these values using the Mouse application in Control Panel. An application obtains and sets these values with the SystemParametersInfo function. The system applies two tests to the specified relative mouse motion when applying acceleration. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse acceleration level is not zero, the operating system doubles the distance. If the specified distance along either the x- or y-axis is greater than the second mouse threshold value, and the mouse acceleration level is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion along the x- or y-axis by up to four times.Once acceleration has been applied, the system scales the resultant value by the desired mouse speed. Mouse speed can range from 1 (slowest) to 20 (fastest) and represents how much the pointer moves based on the distance the mouse moves. The default value is 10, which results in no additional modification to the mouse motion. The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can write a dynamic-link library (DLL) that communicates directly to the tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL returns the extra information. Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.
The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function. Windows NT/2000/XP: This function has been superseded. Use SendInput instead.VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // function options
ULONG_PTR dwExtraInfo // additional keystroke data
);
Parameters
bVk
[in] Specifies a virtual-key code. The code must be a value in the range 1 to 254. For a complete list, see Virtual-Key Codes.
bScan
This parameter is not used.
dwFlags
[in] Specifies various aspects of function operation. This parameter can be one or more of the following values. Value Meaning
KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed.
dwExtraInfo
[in] Specifies an additional value associated with the key stroke.
Return Values
This function has no return value. Res
An application can simulate a press of the PRINTSCRN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT. Windows NT/2000/XP: The keybd_event function can toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK keys. Windows 95/98/Me: The keybd_event function can toggle only the CAPS LOCK and SCROLL LOCK keys. It cannot toggle the NUM LOCK key.Example Code
The following sample program toggles the NUM LOCK light by using keybd_event() with a virtual key of VK_NUMLOCK. It takes a Boolean value that indicates whether the light should be turned off (FALSE) or on (TRUE). The same technique can be used for the CAPS LOCK key (VK_CAPITAL) and the SCROLL LOCK key (VK_SCROLL). #include <windows.h> void SetNumLock( BOOL bState )
{
BYTE keyState[256]; GetKeyboardState((LPBYTE)&keyState);
if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
(!bState && (keyState[VK_NUMLOCK] & 1)) )
{
// Simulate a key press
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 ); // Simulate a key release
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
} void main()
{
SetNumLock( TRUE );
}
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.