python - CGEventPost does not always move the mouse macOS -
i have been encountering issues when trying move mouse programmatically in macos sierra using quartz event services in python environment.
for example:
when run script:
from quartz.coregraphics import cgeventcreatemouseevent quartz.coregraphics import cgeventpost quartz.coregraphics import kcgmousebuttonleft quartz.coregraphics import kcgeventmousemoved quartz.coregraphics import kcghideventtap def mousemove(x, y): event = cgeventcreatemouseevent(none, kcgeventmousemoved, (x, y), kcgmousebuttonleft) cgeventpost(kcghideventtap, event) mousemove(100, 100)
everything works great , mouse gets moved (x: 100, y: 100)
.
however, reason procedure does not manage move mouse in applications. in case macbook running call of duty: modern warfare 2 on steam , moving mouse in manner not register in application interestingly enough still able generate mouse clicks in application using cgeventpost
not mouse movements.
so i've done research try figure out why happening , closest thing find online relating problem this question on , reason mention because i'm wondering if in linked question need call method similar cgeventsetintegervaluefield
instead of updating kcgmouseeventclickstate
update mouse event pertaining movement of mouse application know mouse has indeed moved. have not found such method in cgeventfield documentation , feel i'm missing or maybe isn't involved problem lead find.
please help. appreciate suggestions might have.
i found answer.
i changed line:
event = cgeventcreatemouseevent(none, type, (x, y), kcgmousebuttonleft) cgeventpost(kcghideventtap, event)
to this:
cgpostmouseevent((x, y), true, 0, false)
and of course imported: cgpostmouseevent
as result, moving mouse works everywhere , in applications. reason why works because turns out cgpostmouseevent
occurs on deeper level of local machine cgeventpost
.
Comments
Post a Comment