title: How do I get the Process Serial Number of my own process?
body: <p>I am trying to install an event tap for my own process to intercept mouse events.</p>
  
  <p>For this I found the function <a href="https://developer.apple.com/documentation/coregraphics/1454828-cgeventtapcreateforpsn?language=objc" rel="nofollow noreferrer">CGEventTapCreateForPSN</a> which expects a process' serial number as its first parameter. How do I get the PSN of my <em>own</em> process? <code>GetCurrentProcess</code> is deprecated, <code>GetProcessInformation</code> has also been removed.</p>
  
  <p>I know about <code>CGEventTapCreate</code> 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 <a href="https://stackoverflow.com/questions/29403795/cgeventtapcreateforpsn-in-mavericks-getcurrentprocess-deprecated">CGEventTapCreateForPid</a> 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.</p>
  
  <p>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.</p>