gpt4 book ai didi

cocoa - 从代码发送 MouseEvent 到 NSView (WebView)

转载 作者:行者123 更新时间:2023-12-03 17:07:35 24 4
gpt4 key购买 nike

我正在尝试将鼠标事件(MouseClick 或 RightMouseClick)发送到 NSView...在我的例子中是 WebView,其中包含已加载的网站。我想编写一些对链接等的点击脚本。如何创建 NSEvent 并将其发送到 WebView 来执行点击?

非常感谢

克斯曼

最佳答案

这有点晚了;也许你找到了,也许你没有。不过,我最近不得不弄清楚这一点,所以我将在这里记录下来,希望对某人有所帮助。

NSPoint where;
where.x = x;
where.y = y;
NSView* resp = [someView hitTest:where];
NSEventType evtType = NSLeftMouseDown;
NSEvent *mouseEvent = [NSEvent mouseEventWithType:evtType
location:where
modifierFlags:nil
timestamp:GetCurrentEventTime()
windowNumber:0
context:[o->helper context]
eventNumber:nil
clickCount:1
pressure:nil];
[resp mouseDown:mouseEvent];

关于cocoa - 从代码发送 MouseEvent 到 NSView (WebView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3873688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com