English 中文(简体)
How do I create keyboard shortcuts programmatically in KDE?
原标题:

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,

最佳回答

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.

问题回答

暂无回答




相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签