我可以将跨平台全局热键应用程序与我的应用程序打包在一起吗?

发布于 2024-08-22 12:13:22 字数 199 浏览 5 评论 0原文

因此,我制作了跨平台应用程序,我需要通过全局键命令将其关闭,而我正在使用的 sdk 无法做到这一点。我想知道是否有任何现有的应用程序可以与我的应用程序打包在一起作为我的应用程序的全局热键管理器(允许这样做的许可证)。问题在于它的跨平台方面。我找到了很多应用程序,但我找到了单独适用于 Windows、OS X 或 Linux/Gnome 的应用程序。有什么东西是所有这些合而为一的吗?

So, I have cross platform application that I made, I need to fire it off on a global key command, which the sdk I am using is not able to do. I was wondering if there is any existing app that I could package with my app to act as the global hotkey manager for my application (license that would allow that). The problem is the cross-platform side of it. I have found many apps, but I have found ones for Windows, OS X or Linux/Gnome individually. Is there anything that is all of these in one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的黑色迷你裙 2024-08-29 12:13:22

我还没有找到这样的热键管理应用程序。

但由于您开发自己的应用程序,这个跨平台库可能就足够了:
https://pkg.go.dev/golang.design/x/ hotkey#section-readme

引用页面的位:

热键 PkgGoDev 热键

<小时>

Go 中的跨平台热键包

导入“golang.design/x/hotkey”

功能

<小时>

  • 跨平台支持:macOS、Linux (X11) 和 Windows
  • 全局热键注册,无需关注窗口

...

谁在使用这个包?

<小时>

构建此软件包的主要目的是支持 midgard 项目。

要了解更多项目,请查看我们的 wiki 页面。

许可证

<小时>

麻省理工学院 | © 2021 golang.design Initiative 作者,作者:欧长坤

对于以下具体情况,您有何看法?

概述

<小时>

包热键提供了注册系统级全局热键快捷方式的基本设施,以便在用户触发所需的热键时可以通知应用程序。热键必须是修饰符和单个键的组合。

注意平台特定详细信息:

  • 在 macOS 上,由于操作系统限制(其他平台没有此限制),热键事件必须在“主线程”上处理。因此,为了正确使用这个包,必须在主线程上启动操作系统主事件循环,对于独立的应用程序,使用 主线程 包。是可能的。它是不必要的或基于其他 GUI 框架的应用程序,例如 fyne、ebiten 或 Gio。有关更多示例,请参阅“示例”。

  • 在 Linux (X11) 上,当 X 服务器中启用 AutoRepeat 时,Keyup 会在 Keydown 继续时自动连续触发。

  • 在 Linux (X11) 上,某些键可能会映射到多个 Mod 键。要正确注册按键组合,必须使用正确的基础按键代码组合。例如,常规 Ctrl+Alt+S 可能会注册为:Ctrl+Mod2+Mod4+S。

  • 如果此软件包不包含所需的密钥,则始终可以向 API 提供密钥代码。例如,如果按键代码为0x15,则对应的按键为hotkey.Key(0x15)

以下是一个最小示例:

包主要

进口 (
  “日志”

  “golang.design/x/热键”
  “golang.design/x/hotkey/mainthread”
)

func main() { mainthread.Init(fn) } // 在 Fyne、Ebiten 或 Gio 中使用时不需要。
函数 fn() {
  hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS)
  错误 := hk.Register()
  如果错误!= nil {
      log.Fatalf("热键:注册热键失败:%v", err)
  }

  log.Printf("热键:%v 已注册\n", hk)
  <-hk.Keydown()
  log.Printf("热键:%v 已按下\n", hk)
  <-hk.Keyup()
  log.Printf("热键:%v 已启动\n", hk)
  hk.Unregister()
  log.Printf("热键: %v 未注册\n", hk)
}

我不是作者/相关人员,只是一个谷歌搜索绕过者。干杯!

I haven't found such hotkey management app yet.

But since you develop your own app, this cross-platform library might suffice:
https://pkg.go.dev/golang.design/x/hotkey#section-readme

Quoting bits of the page:

hotkey PkgGoDev hotkey


cross platform hotkey package in Go

import "golang.design/x/hotkey"

Features


  • Cross platform supports: macOS, Linux (X11), and Windows
  • Global hotkey registration without focus on a window

...

Who is using this package?


The main purpose of building this package is to support the midgard project.

To know more projects, check our wiki page.

License


MIT | © 2021 The golang.design Initiative Authors, written by Changkun Ou.

What do you think of the following specifics?

Overview


Package hotkey provides the basic facility to register a system-level global hotkey shortcut so that an application can be notified if a user triggers the desired hotkey. A hotkey must be a combination of modifiers and a single key.

Note platform specific details:

  • On macOS, due to the OS restriction (other platforms does not have this restriction), hotkey events must be handled on the "main thread". Therefore, in order to use this package properly, one must start an OS main event loop on the main thread, For self-contained applications, using mainthread package. is possible. It is uncessary or applications based on other GUI frameworks, such as fyne, ebiten, or Gio. See the "examples" for more examples.

  • On Linux (X11), when AutoRepeat is enabled in the X server, the Keyup is triggered automatically and continuously as Keydown continues.

  • On Linux (X11), some keys may be mapped to multiple Mod keys. To correctly register the key combination, one must use the correct underlying keycode combination. For example, a regular Ctrl+Alt+S might be registered as: Ctrl+Mod2+Mod4+S.

  • If this package did not include a desired key, one can always provide the keycode to the API. For example, if a key code is 0x15, then the corresponding key is hotkey.Key(0x15).

THe following is a minimum example:

package main

import (
  "log"

  "golang.design/x/hotkey"
  "golang.design/x/hotkey/mainthread"
)

func main() { mainthread.Init(fn) } // Not necessary when use in Fyne, Ebiten or Gio.
func fn() {
  hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS)
  err := hk.Register()
  if err != nil {
      log.Fatalf("hotkey: failed to register hotkey: %v", err)
  }

  log.Printf("hotkey: %v is registered\n", hk)
  <-hk.Keydown()
  log.Printf("hotkey: %v is down\n", hk)
  <-hk.Keyup()
  log.Printf("hotkey: %v is up\n", hk)
  hk.Unregister()
  log.Printf("hotkey: %v is unregistered\n", hk)
}

I am not author/a related person, just a googling bypasser. Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文