19 个版本
新 2.0.0-rc.1 | 2024 年 8 月 17 日 |
---|---|
2.0.0-beta.9 | 2024 年 7 月 31 日 |
2.0.0-beta.3 | 2024 年 3 月 21 日 |
2.0.0-alpha.6 | 2023 年 12 月 20 日 |
2.0.0-alpha.0 | 2023 年 5 月 24 日 |
#1036 在 GUI
2,073 每月下载
用于 qwit-desktop
83KB
408 代码行
注册全局快捷键。
- 支持的平台:Windows、Linux 和 macOS。
安装
此插件需要至少 1.75 版本的 Rust
我们推荐三种安装方法。
- 使用 crates.io 和 npm(最简单,需要您信任我们的发布管道)
- 直接从 Github 使用 git 标签/版本哈希拉取源代码(最安全)
- 使用 Git 子模块在此 tauri 项目中安装此存储库,然后使用文件协议导入源代码(最安全,但使用不便)
通过将以下内容添加到您的 Cargo.toml
文件中安装核心插件
src-tauri/Cargo.toml
# you can add the dependencies on the `[dependencies]` section if you do not target mobile
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
tauri-plugin-global-shortcut = "2.0.0-rc"
# alternatively with Git:
tauri-plugin-global-shortcut = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
您可以使用您首选的 JavaScript 包管理器安装 JavaScript 客户端绑定
注意:由于大多数 JavaScript 包管理器无法从 git monorepos 安装包,我们为每个插件提供了只读镜像。这使得安装选项 2 更易于使用。
pnpm add @tauri-apps/plugin-global-shortcut
# or
npm add @tauri-apps/plugin-global-shortcut
# or
yarn add @tauri-apps/plugin-global-shortcut
# alternatively with Git:
pnpm add https://github.com/tauri-apps/tauri-plugin-global-shortcut#v2
# or
npm add https://github.com/tauri-apps/tauri-plugin-global-shortcut#v2
# or
yarn add https://github.com/tauri-apps/tauri-plugin-global-shortcut#v2
用法
首先,您需要将核心插件注册到 Tauri 中
src-tauri/src/main.rs
fn main() {
tauri::Builder::default()
.setup(|app| {
#[cfg(desktop)]
{
use tauri::Manager;
use tauri_plugin_global_shortcut::{Code, Modifiers, ShortcutState};
app.handle().plugin(
tauri_plugin_global_shortcut::Builder::new()
.with_shortcuts(["ctrl+d", "alt+space"])?
.with_handler(|app, shortcut, event| {
if event.state == ShortcutState::Pressed {
if shortcut.matches(Modifiers::CONTROL, Code::KeyD) {
let _ = app.emit("shortcut-event", "Ctrl+D triggered");
}
if shortcut.matches(Modifiers::ALT, Code::Space) {
let _ = app.emit("shortcut-event", "Alt+Space triggered");
}
}
})
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
之后,所有插件 API 都可通过 JavaScript 绑定访问
import { register } from "@tauri-apps/plugin-global-shortcut";
await register("CommandOrControl+Shift+C", (event) => {
if (event.state === "Pressed") {
console.log("Shortcut triggered");
}
});
贡献
接受 PR。在提交拉取请求之前,请务必阅读贡献指南。
合作伙伴
|
有关赞助商的完整列表,请访问我们的 网站 和 Open Collective。
许可证
代码:© 2015 - 现在 - The Commons Conservancy 的 Tauri 程序。
适用时为 MIT 或 MIT/Apache 2.0。
依赖关系
~17–57MB
~886K SLoC