我运行以下代码:
LPPOINT pp = new POINT;
GetCursorPos(pp);
while(1){
PostMessage(GetDesktopWindow(), WM_LBUTTONDBLCLK, 0, MAKELPARAM(pp->x, pp->y));
Sleep(1000);
}
它不会单击光标指示的点,而是打开和关闭“开始”菜单 请告诉我怎么了
答案 0 :(得分:1)
将// GET: Admin/Shop/Products
public ActionResult MyContractors(int? catId)
{
using (Db db = new Db())
{
UserDTO user = db.Users.Where(x => x.Username == User.Identity.Name).FirstOrDefault();
int userId = user.UserId;
// Declare a list of ProductVM
List<ContractorVM> Contractors = db.Contractors.Where(x => x.UserId == userId).ToArray().Select(x => new ContractorVM(x)).ToList();
// Populate categories select list
ViewBag.ContractorCategories = new SelectList(db.ContractorCategories.ToList(), "ContractorCategoryId", "ContractorCategoryName");
// Set selected category
ViewBag.SelectedCat = catId.ToString();
}
// Return view with list
return View(Contractors);
}
发送到任意窗口句柄或桌面将不会模拟鼠标单击。
但是,您可以使用SendInput
,它可以模拟给定屏幕坐标(而不是窗口句柄,窗口或客户端坐标)的鼠标单击。此代码将模拟在当前光标位置处的左键单击:
WM_LBUTTONDBLCLK
请注意,您也可以使用mouse_event
,但是根据MSDN上的官方文档,INPUT in[2]; // 0 = left dn, 1 = left up
ZeroMemory(in, sizeof(INPUT) * 2);
in[0].type = INPUT_MOUSE;
in[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
in[1].type = INPUT_MOUSE;
in[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(2, in, sizeof(INPUT));
是首选。