以下用于右鍵單擊的代碼有效:
auto event = CGEventCreateMouseEvent(nullptr, kCGEventOtherMouseDown,
{x, y}, kCGMouseButtonRight);
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 1);
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
然而,完全相同的代碼 withkCGMouseButtonRight替換為kCGMouseButtonLeft沒有。
旁注:我想知道這是否是由于后一個事件沒有注冊,所以我嘗試了一個“關鍵測驗”,發現這兩個事件都注冊為中間按鈕(盡管其他應用程式的右鍵單擊按預期作業)。
為什么左鍵單擊不起作用,我該如何制作?
uj5u.com熱心網友回復:
我能夠通過使用kCGEventLeftMouseDown代替kCGEventOtherMouseDown. 這與Apple 檔案有關kCGEventOtherMouseDown:
Specifies a mouse down event with one of buttons 2-31.
(左 = 0,右 = 1,中心 = 2,額外按鈕 = 3-31)
這也解釋了為什么網站將左右注冊為中心,但它沒有解釋為什么右鍵單擊仍然有效(打開背景關系選單),但我想這就是您在不正確查看檔案時必須處理的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/337982.html
