触发全局快捷方式时,哪个应用程序具有焦点 [英] Which app has the focus when a global shortcut is triggered

查看:78
本文介绍了触发全局快捷方式时,哪个应用程序具有焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用全局快捷方式弹出对话框. 但是我想根据触发快捷方式时具有焦点的应用程序来填充对话框.

I use a global shortcut to popup a dialog. But I would like to fill the dialog depending on the application having the focus at the moment the shortcut is triggered.

但是我找不到办法.我在此处阅读了扩展代码 但是很难知道如何修改代码以及如何重新编译电子.

But I can not find a way to do it. I read the extension code here but it's hard to know how to modify the code, and how to recompile electron.

如果有人有一个指针,将不胜感激:)

If someone have a pointer, that will be greatly appreciated :)

推荐答案

我自己找到了一个答案,看来最前端的应用程序(至少在OSX上是这样)仍然是调用前重点关注的应用程序.

I found an answer myself, it looks that the frontmost app (at least on OSX) it still the app that had the focus before the invokation.

这是我的ClojureScript代码,用于查找应用程序信息

Here is my ClojureScript code to find the app info

(defn- get-current-app-info-osx
  "Return info about the current frontmost application on OSX"
  []
  (let [remote  (js/require "remote")
        nodobjc (js/require "nodobjc")]
    (.framework nodobjc "AppKit")
    (let [workspace (.NSWorkspace nodobjc "sharedWorkspace")
      app       (workspace "frontmostApplication")
      app-name  (str (app "localizedName"))
      app-id    (str (app "bundleIdentifier"))]
  {:name app-name
   :id   app-id})))

这篇关于触发全局快捷方式时,哪个应用程序具有焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆