findout if my terminal app in os x have focus lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- robbyyu · 2020-06-15 21:54 Hi, I am writing terminal application in freepascal on macos x and need to detect does my application have focus. It is part of screen and keyboard libraries I am working on. Since I need to differentiate between ctrl/m and enter but also detect for example alt/t which is usually used for composed unicode characters, ncourses don't do the job, plus I want to reduce dependencies as much as possible. So far I have managed to query user space keyboard driver, but I am geting global keyups and keydowns even when my application doesn't have focus. Does enybody knows how can I check if my terminal application have keyboard focus? I would like to avoid Carbon, since it seems that it will be depreciated in some time in the future. Thx robby p.s. I use plain fpc without lazarus, and do not need gui. ---------------------------------------------------------------------- trev · 2020-06-15 22:32 Quote from: robbyyu on June 15, 2020, 11:54:06 pm I would like to avoid Carbon, since it seems that it will be depreciated in some time in the future. Apple deprecated the Carbon framework years ago in macOS 10.8 (Mountain Lion) in 2012 and actually removed almost all of the Carbon framework from macOS 10.15 (Catalina) in 2019 when it dropped all support for running 32 bit exectuables. ---------------------------------------------------------------------- robbyyu · 2020-06-16 00:36 I am stil on Sierra, so didn't noticed it ---------------------------------------------------------------------- trev · 2020-06-16 01:53 On your main question, see https://stackoverflow.com/questions/38659839/how-to-capture-process- space-key-events-in-osx-command-line-tool-corefoundation ---------------------------------------------------------------------- robbyyu · 2020-06-16 18:10 Hey trav, thanks for promt reply,I'll check it and report back cheers, robby ---------------------------------------------------------------------- robbyyu · 2020-06-16 18:59 Hey trev, link to post you have sent me is quite interesting, alltought a bit outdated. It does not seem resolved and frontmostapplication is always terminal (or whatever I use to start my executable). I am not doing event taps, instead I used user space port to keyboard device and installed val handler. It seem possible to do simmilar thing with iokit and interrupt handler. Unfortunately it seems that it is not that easy to find which process have keyboard focus (there seems to be possible to know which application have it, but this is just partial solution since terminal might have multiple windows opened) but this is actually what I need ... cheers, robby p.s. my code is attached if anyone is interested in it.