How do I get the Process Serial Number of my own process?

296 Views Asked by At

I am trying to install an event tap for my own process to intercept mouse events.

For this I found the function CGEventTapCreateForPSN which expects a process' serial number as its first parameter. How do I get the PSN of my own process? GetCurrentProcess is deprecated, GetProcessInformation has also been removed.

I know about CGEventTapCreate but from what I understand that installs a system-wide hook and that doesn't sound like a good idea or something I'd like to do. I also know about CGEventTapCreateForPid but I can't use that because I am also targeting older MacOSX versions that don't have that function and it also appears to be undocumented so who knows when it will go away.

FYI, I don't own the actual program, my code is only loaded into the process as a dynamic library so I cannot just modify the program's code or anything like that.

0

There are 0 best solutions below