Keyconfig extension: Difference between revisions

From MozillaZine Knowledge Base
Jump to navigationJump to search
(→‎Tips: mention Compose window gotcha)
(new section - finding code using DOMi)
Line 2: Line 2:
The extension [http://dorando.emuverse.com/projects/mozilla/readme.html Keyconfig] allows you to configure keyboard shortcuts. It works with [[Firefox]], [[Thunderbird]], and (probably) the [[Mozilla Suite]]. Shortcuts defined via a key can be changed. For more details, [http://www.extensionsmirror.nl/index.php?showtopic=254].
The extension [http://dorando.emuverse.com/projects/mozilla/readme.html Keyconfig] allows you to configure keyboard shortcuts. It works with [[Firefox]], [[Thunderbird]], and (probably) the [[Mozilla Suite]]. Shortcuts defined via a key can be changed. For more details, [http://www.extensionsmirror.nl/index.php?showtopic=254].


===Keyconfig's user interface===
==Keyconfig's user interface==
Keyconfig has a user interface for working with keyboard shortcuts.  For example, if you have installed the Keyconfig extension, here is how you can compact the current folder in Thunderbird by using the shortcut Alt-C:<ol>
Keyconfig has a user interface for working with keyboard shortcuts.  For example, if you have installed the Keyconfig extension, here is how you can compact the current folder in Thunderbird by using the shortcut Alt-C:<ol>
<li>In Thunderbird, choose: Tools &ndash; Keyconfig...  The Keyconfig dialog opens.</li>
<li>In Thunderbird, choose: Tools &ndash; Keyconfig...  The Keyconfig dialog opens.</li>
Line 15: Line 15:
</ol>
</ol>


===Tips===
==Finding code for keys==
* You can add preferences for custom keys to  the [[prefs.js file]] in your [[profile folder]] to get the described results. All instances of Firefox, Thunderbird, or Mozilla must be closed before editing this file. After editing start the browser and open the Keyconfig window to set your keyboard shortcut. '''Attention: Don't add these preferences to your [[user.js file|user.js]] file because they are applied again with the next start and the assigned keyboard shortcuts will be deleted.'''
See the ''[[#Examples|Examples]]'' section below for articles that contain many code samples.
* If you have technical knowledge of Mozilla applications, then you can use the [[DOM Inspector]] extension to discover how existing elements in the user interface work, helping you to develop code for new keyboard shortcuts.
 
* The Compose window for mail messages is recycled after the first message, so you do not really get a new window for subsequent messagesTo get a new Compose window so that keyconfig loads its keys there, close and restart the application.
When you want to add a key for an action that already exists in the user interface, you can often find the code by using the [[DOM Inspector]] extension. For example, if you have installed the DOM Inspector extension in Thunderbird, here is how you can find the code that opens a saved message:<ol>
<li>Identify the user-interface element that performs the action. Open the required window if necessary.</li>
<p>In this example, it is the menu item: File &ndash; Open saved Message... in Thunderbird's main window.</p>
<li>In the main window, choose Tools &ndash; DOM Inspector.</li>
<li>In the DOM Inspector window, choose File &ndash; Inspect a Window and choose the window where you identified the user-interface element.</li>
<p>In this example, it is Thunderbird's main window.</p>
<li>In the DOM Inspector window, choose Search &ndash; Select Element By Click (or press the button at the left).  The button depresses.  Now it will act on the first thing in Thunderbird that you click, so you must not click on anything until you find the user-interface element that you identified.</li>
<li>Use your keyboard to return to the window where you identified the user-interface element, and to navigate to that element. Click that user-interface element so that DOM Inspector finds it.</li>
<p>In this example, return to Thunderbird's main window. Press Alt-F to open the File menu.  Now that you can see the Open Saved Message... item, click it.  (Cancel the file picker that it opens.)</p>
<li>In DOM Inspector's left-hand pane, check that the appropriate element is now selected.</li>
<p>In this example, it is a <tt>menuitem</tt> element.</p>
<li>In DOM Inspector's right-hand pane, ensure that that DOM Node is selected at the top.  Look for the node name: <tt>oncommand</tt> &nbsp; The corresponding node value is the code you need for your key.</li>
<p>In this example, the code is: <tt>MsgOpenFromFile();</tt></p>
</ol>
 
If the element has no <tt>oncommand</tt> node, but only a <tt>command</tt> node, then you might be able to find the code by searching.  Note the exact value of the command.  It is case sensitive.  In DOM Inspector, choose Search &ndash; Find Nodes... and specify that command as the ID.  If you find a matching <tt>command</tt> element with an <tt>oncommand</tt> node, then you can use the code there in your key.
 
In some cases DOM Inspector cannot show you the code, because it is in a separate fileFinding the code in these cases is beyond the scope of this article.


===Template===
==Tips==
Here is a template for Keyconfig preferences that you add to your prefs.js file:
<ul>
<li>You can add preferences for custom keys to  the [[prefs.js file]] in your [[profile folder]] to get the described results. All instances of Firefox, Thunderbird, or Mozilla must be closed before editing this file. After editing start the browser and open the Keyconfig window to set your keyboard shortcut. '''Attention: Don't add these preferences to your [[user.js file|user.js]] file because they are applied again with the next start and the assigned keyboard shortcuts will be deleted.'''</li>
<p>Here is a template for Keyconfig preferences that you add to your prefs.js file:</p>
</ul>
<div style="margin-left:2em;">
  user_pref("keyconfig.main.xxx_key__<font style="color:#0000FF">NAME</font>", "!][][][<font style="color:#FF0000">FUNCTION</font>");
  user_pref("keyconfig.main.xxx_key__<font style="color:#0000FF">NAME</font>", "!][][][<font style="color:#FF0000">FUNCTION</font>");
</div>
* The Compose window for mail messages is recycled after the first message, so you do not really get a new window for subsequent messages.  To get a new Compose window so that keyconfig loads its keys there, close and restart the application.
* To get a new main window, you do not usually need to close the application.  For example, in Firefox you can choose File &ndash; New Window, or in Thunderbird you can double-click a folder.  When the new window opens, close the old one (where your keyconfig changes are not active).


===Examples===
==Examples==
* [[Keyconfig extension: Firefox | Custom Keys for Firefox]]
* [[Keyconfig extension: Firefox | Custom Keys for Firefox]]
* [[Keyconfig extension: Thunderbird | Custom Keys for Thunderbird]]
* [[Keyconfig extension: Thunderbird | Custom Keys for Thunderbird]]

Revision as of 13:42, 26 March 2007

The extension Keyconfig allows you to configure keyboard shortcuts. It works with Firefox, Thunderbird, and (probably) the Mozilla Suite. Shortcuts defined via a key can be changed. For more details, [1].

Keyconfig's user interface

Keyconfig has a user interface for working with keyboard shortcuts. For example, if you have installed the Keyconfig extension, here is how you can compact the current folder in Thunderbird by using the shortcut Alt-C:

  1. In Thunderbird, choose: Tools – Keyconfig... The Keyconfig dialog opens.
  2. At the bottom of the Keyconfig dialog, press the button "Add a new key". The Key editor dialog opens.
  3. Name the key: Compact This Folder (You can use any name—it does not affect the operation of the key.)
  4. Copy and paste the following code sample where you see the comment /*CODE*/:
  5. goDoCommand("cmd_compactFolder")
  6. Press OK to close the Key editor.
  7. Go to the field at the bottom of the Keyconfig dialog, and press the key combination Alt+C. (Do not type the characters A l t + C, but instead hold down the Alt key and press the C key.)
  8. Press the Apply button, then the Close button.
  9. Restart Thunderbird.

Finding code for keys

See the Examples section below for articles that contain many code samples.

When you want to add a key for an action that already exists in the user interface, you can often find the code by using the DOM Inspector extension. For example, if you have installed the DOM Inspector extension in Thunderbird, here is how you can find the code that opens a saved message:

  1. Identify the user-interface element that performs the action. Open the required window if necessary.
  2. In this example, it is the menu item: File – Open saved Message... in Thunderbird's main window.

  3. In the main window, choose Tools – DOM Inspector.
  4. In the DOM Inspector window, choose File – Inspect a Window and choose the window where you identified the user-interface element.
  5. In this example, it is Thunderbird's main window.

  6. In the DOM Inspector window, choose Search – Select Element By Click (or press the button at the left). The button depresses. Now it will act on the first thing in Thunderbird that you click, so you must not click on anything until you find the user-interface element that you identified.
  7. Use your keyboard to return to the window where you identified the user-interface element, and to navigate to that element. Click that user-interface element so that DOM Inspector finds it.
  8. In this example, return to Thunderbird's main window. Press Alt-F to open the File menu. Now that you can see the Open Saved Message... item, click it. (Cancel the file picker that it opens.)

  9. In DOM Inspector's left-hand pane, check that the appropriate element is now selected.
  10. In this example, it is a menuitem element.

  11. In DOM Inspector's right-hand pane, ensure that that DOM Node is selected at the top. Look for the node name: oncommand   The corresponding node value is the code you need for your key.
  12. In this example, the code is: MsgOpenFromFile();

If the element has no oncommand node, but only a command node, then you might be able to find the code by searching. Note the exact value of the command. It is case sensitive. In DOM Inspector, choose Search – Find Nodes... and specify that command as the ID. If you find a matching command element with an oncommand node, then you can use the code there in your key.

In some cases DOM Inspector cannot show you the code, because it is in a separate file. Finding the code in these cases is beyond the scope of this article.

Tips

  • You can add preferences for custom keys to the prefs.js file in your profile folder to get the described results. All instances of Firefox, Thunderbird, or Mozilla must be closed before editing this file. After editing start the browser and open the Keyconfig window to set your keyboard shortcut. Attention: Don't add these preferences to your user.js file because they are applied again with the next start and the assigned keyboard shortcuts will be deleted.
  • Here is a template for Keyconfig preferences that you add to your prefs.js file:

user_pref("keyconfig.main.xxx_key__NAME", "!][][][FUNCTION");
  • The Compose window for mail messages is recycled after the first message, so you do not really get a new window for subsequent messages. To get a new Compose window so that keyconfig loads its keys there, close and restart the application.
  • To get a new main window, you do not usually need to close the application. For example, in Firefox you can choose File – New Window, or in Thunderbird you can double-click a folder. When the new window opens, close the old one (where your keyconfig changes are not active).

Examples