如何在 KDE 中以编程方式创建键盘快捷键?

发布于 2024-09-09 10:45:57 字数 594 浏览 10 评论 0原文

我可以使用控制中心界面的输入操作部分为 Ctrl-F1 和 Ctrl-F2 创建键盘快捷键,使它们启动脚本。目前感兴趣的平台是 CentOS 5 上的 KDE 3.5,但 4.x 也是 直接利益较少。

然而,我需要的是从 shell 脚本创建相同的快捷方式,在安装 RPM 后运行:此 RPM 创建一个用户,然后完全预配置其 KDE 环境。到目前为止,我已经能够执行类似的操作

cat > kdesktoprc <<- EOM
[Desktop0]
WallpaperMode=NoWallpaper
EOM

,然后在第一次登录时,KDE 设置将从那里正常启动。 我想我想做的是预置这个特定帐户,但我 不想干扰任何其他当前或未来的帐户 同一个主机。

不幸的是,我无法使用输入进行相同的工作 Actions,其配置稍微复杂一些。尝试之前 为了进一步解决这个问题,我决定询问是否有更好的方法。

换句话说,是否有一个命令来创建键盘快捷键(我没有 我认为我可以使用 DCOP,因为当时 KDE 不会运行)?

我浏览了 kconf_update 机制的提示,但无法确定它是否适合我的用例:是否有可用的参考?

先感谢您,

I am able to create keyboard shortcuts for Ctrl-F1 and Ctrl-F2, making them launch a script, using the Control Center interface, Input Actions section. The platform of interest is KDE 3.5 on CentOS 5 at present, but 4.x is also of
less immediate interest.

What I need, however, is to create the same shortcuts from a shell script, run after installation of an RPM: this RPM creates a user and then preconfigures its KDE environment completely. So far, I've been able to do stuff like

cat > kdesktoprc <<- EOM
[Desktop0]
WallpaperMode=NoWallpaper
EOM

and then upon first login the KDE setup would pick up from there just fine.
I guess what I am trying to do is preseeding this specific account, but I
don't want to interfere with any other present or future account on the
same host.

Unfortunately, I have not been able to make the same work with Input
Actions, whose configuration is somewhat more involved. Before attempting
to unravel it further, I decided to ask if there was a better way.

In other words, is there a command to create a keyboard shortcut (I don't
think I can use DCOP, because KDE would not be running at the time) ?

I skimmed hints to the kconf_update mechanism, but was unable to ascertain if it was appropriate for my use case: is there a reference available ?

Thank you in advance,

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

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

发布评论

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

评论(1

蓝色星空 2024-09-16 10:45:57

我找到了一种似乎有效的方法。首先,我创建一个 .khotkeys 文件,
将其命名为 zzz.khotkeys,并将其存储在 /usr/hsare/apps/khotkeys 下。一个好的
其起点是 printscreen.khotkeys 文件。

此 .khotkeys 文件有两个部分,一个包含热键定义的 [Data] 部分,以及一个 [Main] 部分,其中我们拥有其他键,

Id=zzz

用于记住哪些键定义已导入。

要使 zzz.khotkeys 中的定义生效,您可以使用它

/usr/lib/kconf_update_bin/khotkeys_update --id zzz

,它似乎调用与中的“导入”按钮等效的功能
“输入操作”用户界面。

这一步在我的场景中遇到了许多障碍,即运行所有
RPM 安装的 %post 脚本中的上述内容。

首先,如果 khotkeys_update 无法联系 X 服务器,它就会失败;在
表面上这似乎很愚蠢,因为它只需要执行文本整理,
但这可以通过将其调用放在 .kde/Autostart 中的 .desktop 文件中来解决。

其次,khotkeys_update 看起来并不完全像一个已发布的接口
随着时间的推移可以信赖;因为这是针对 CentOS/KDE 3.5 的
在一个预计不会发生任何变化的环境中,我很荣幸能够
认为这是一个小问题。如果有已发布的(shell)接口
执行导入,我找不到它(我没有调查DCOP)。

最后,同样的脚本直接定制了其他配置
.kde/share/config 下的文件还在 .kde/Autostart 下添加了一个名为
zzz-keys.desktop 看起来像是

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=ZZZ Hotkeys
Comment=Ensure ZZZ keyboard shortctus are available
Exec=/usr/lib/kconf_update_bin/khotkeys_update --id zzz

第一次添加热键(它们最终位于 khotkeysrc 内)
并且在后续调用中被跳过,因为 khotkeysrc 包含一个密钥
名称 AlreadyInstalled 也更新为包含“zzz”等
后续运行 khotkeys_update 会找到它并且不会添加重复项。

I found an approach which appears to work. First, I create a .khotkeys file,
call it zzz.khotkeys, and store it under /usr/hsare/apps/khotkeys. A good
starting point for that is the printscreen.khotkeys file.

This .khotkeys file has two sections, a [Data] section with the hotkey definition(s), and a [Main] section where among other keys we have

Id=zzz

which is used to remember which key definitions have been already imported.

To put the definitions in zzz.khotkeys into effect, you could use this

/usr/lib/kconf_update_bin/khotkeys_update --id zzz

which seems to invoke functionality equivalent to the "Import" button in
the "Input Actions" user interface.

This step incurs a number of obstacles in my scenario, which is running all
of the abovce in the %post script of an RPM install.

First, khotkeys_update fails if it cannot contact an X server; on the
surface this seems silly, as it should only need to perform text wrangling,
but this can be addressed by placing its invocation inside a .desktop file in .kde/Autostart.

Second, khotkeys_update does not exactly look like a published interface
which can be relied upon over time; since this is for CentOS/KDE 3.5 in
a context where little evolution is expected, I enjoy the privilege to
consider this a minor issue. If there is a published (shell) interface to
perform the import, I could not find it (I did not investigate DCOP).

In the end, the same script which directly customized other configuration
files under .kde/share/config also adds under .kde/Autostart a file named
zzz-keys.desktop which looks like

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=ZZZ Hotkeys
Comment=Ensure ZZZ keyboard shortctus are available
Exec=/usr/lib/kconf_update_bin/khotkeys_update --id zzz

which gets the hotkeys added the first time (they end up inside khotkeysrc)
and is skipped on subsequent invocations, because khotkeysrc includes a key
name AlreadyInstalled which is also updated to include "zzz", so on
subsequent runs khotkeys_update finds it and does not add duplicates.

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