XUL Programmer's Reference Manual

<key>

Attributes Common Children
id  * * *
key  
keycode  
command  
alt  
shift  
control  
onkeydown  
onkeyup  
onkeypress  
oncommand  

<key> is a XUL key binding widget. Key bindings define a relationship between between keystroke combinations and functionality in the interface. Keys are typically grouped into keysets.
 
 

 

key
Description
key is an attribute required to specify the primary key of the binding for an event handler. 
Syntax
<key id="string" key="keyboard character" />


Example

<keyset>
   <key id="newKey" key="n" onkeydown="New()" />
   <key id="openKey" key="o" onkeydown="Open()" />
   <key id="saveKey" key="s" onkeydown="Save()" />
</keyset>
Notes
The value of key is case-insensitive, so "S" means the same thing as "s". When there is no modifier specified, the primary key works by itself to prompt the event handler. When a modifier and a key are specified, then both need to be pressed to prompt the event hander.

 

 

keycode
Description
keybode is an optional attribute for specifying keyboard command keys to prompt event handlers.
Syntax
<key id="string" keycode="keyboard character" />
Example
<key id="saveKey" key="s" keycode="VK_HOME" onkeydown="HomePage()" />
Notes
Common keycodes appear in the following table:
 
keycode keyboard display
VK_HOME Home
VK_END End
VK_LEFT Left Arrow
VK_RIGHT Right Arrow
VK_PAGE_UP Page Up key
VK_PAGE_DOWN Page Down key
VK_DELETE Delete key
VK_INSERT Insert key
VK_END End key
VK_F2 (et al) Function keys
VK_ENTER Enter key
 
command
Description
command is an optional attribute for specifying command keys to be used in conjunction with the primary key to prompt event handlers.
Syntax
<key id="string" key="keyboard character" command="[ true | false]" />
Example
<key id="saveKey" key="s" command="true" onkeydown="Save()" />
Notes
The example above defines a key binding for the command + s key combination. The command keys vary from platform to platform, as shown in the following table:
 
Modifier GTK Macintosh Windows
command control command control
alt alt option alt
shift shift shift shift
control control control control
 
alt
Description
alt is an optional attribute for specifying command keys to be used in conjunction with the primary key to prompt event handlers.
Syntax
<key id="string" key="keyboard character" alt="[ true | false]" />
Example
<key id="saveKey" key="s" alt="true" onkeydown="Save()" />
Notes
The example above defines a key binding for the alt + s key combination. The alt keys vary from platform to platform, as shown in the following table:
 
Modifier GTK Macintosh Windows
command control command control
alt alt option alt
shift shift shift shift
control control control control
shift
Description
shift is an optional attribute for specifying command keys to be used in conjunction with the primary key to prompt event handlers.
Syntax
<key id="string" key="keyboard character" shift="[ true | false]" />
Example
<key id="saveKey" key="s" shift="true" onkeydown="Save()" />
Notes
The example above defines a key binding for the shift + s key combination. The modifier keys vary from platform to platform, as shown in the following table:
 
Modifier GTK Macintosh Windows
command control command control
alt alt option alt
shift shift shift shift
control control control control
control
Description
control is an optional attribute for specifying command keys to be used in conjunction with the primary key to prompt event handlers.
Syntax
<key id="string" key="keyboard character" control="[ true | false]" />
Example
<key id="saveKey" key="s" control="true" onkeydown="Save()" />
Notes
The example above defines a key binding for the control + s key combination. The modifier keys vary from platform to platform, as shown in the following table:
 
Modifier GTK Macintosh Windows
command control command control
alt alt option alt
shift shift shift shift
control control control control
onkeydown
Description
onkeydown is an optional attribute for creating event handlers for key bindings. 
Syntax
<key id="string" key="keyboard character" onkeydown="event handler code" />
Example
<key id="saveKey" key="S" onkeydown="Save()" />
Notes
The keydown event is fired when the user first depresses the key specified by the key attribute (and the modifiers). The keypress event is effecctively equivalent to the keydown and keyup events together.

 
 

 

onkeyup
Description
onkeyup is an optional attribute for creating event handlers for key bindings. 
Syntax
<key id="string" key="keyboard character" onkeyup="event handler code" />
Example
<key id="saveKey" key="S" onkeyup="Save()" />
Notes
The keyup event is fired when the user releases the key specified by the key attribute (and the modifiers). The keypress event is effecctively equivalent to the keydown and keyup events together.

 
 
 

 

onkeypress
Description
onkeypress is an optional attribute for creating event handlers for key bindings. 
Syntax
<key id="string" key="keyboard character" onkeypress="event handler code" />
Example
<key id="saveKey" key="S" onkeypress="Save()" />
Notes
The keypress event is fired when the user presses the key specified by the key attribute (and the modifiers). The keypress event is effecctively equivalent to the keydown and keyup events together.

 
 
 

 

oncommand
Description
oncommand is an optional attribute for creating event handlers for key bindings. 
Syntax
<key id="string" key="keyboard character" oncommand="event handler code" />
Example
<key id="saveKey" key="S" oncommand="Save()" />
Notes
XXX. This still has to be updated. The keypress event is fired when the user presses the key specified by the key attribute (and the modifiers). The keypress event is effecctively equivalent to the keydown and keyup events together.

 

 


 

Last updated: 4/12/00 Ian Oeschger