KeyNaming.h


Version: 2.2

Includes: <CoreFoundation/CoreFoundation.h>
Discussion

Copyright © 2001–2008 Jens Ayton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Like UCKeyTranslate(), but much less scary.

Overview



The KeyNaming library converts virtual key codes (as provided by the various event systems) or HID usages codes (as provided by IOKit’s HID interface) to descriptive strings reflecting the current keyboard layout.

Two macros affect the availability of KeyNaming functions. Functions taking virtual key codes as parameters are disabled if KEYNAMING_ENABLE_VKC is defined as zero. Functions taking HID usage codes as parameters are disabled if KEYNAMING_ENABLE_HID is defined as zero. By default, both are set to 1 and dead code stripping is assumed to work.

Cocoa

Normal toll-free bridging rules apply: if calling from Cocoa, cast results to NSString * or NSArray *, and remember to release.



Functions

KeyNamingCopyOneKeyName
Get a name for a key.
KeyNamingCopyKeyNames
Get names for a list of keys.
KeyNamingCopyKeyNamesAsArray
Get names for a list of keys, as a CFArray.
KeyNamingCopyOneKeyNameHID
Get a name for a key.
KeyNamingCopyKeyNamesHID
Get names for a list of keys.
KeyNamingCopyKeyNamesAsArrayHID
Get names for a list of keys, as a CFArray.
KeyNamingSetStringTable
Specifies the string table to use for naming special keys.
KeyNamingSetStringTableAndBundle
Specifies the string table to use for naming special keys.

KeyNamingCopyOneKeyName


Get a name for a key.

CFStringRef KeyNamingCopyOneKeyName(
    uint16_t inVirtualKeyCode);  
Parameters
inVirtualKeyCode
The virtual key code of the key to name.
Return Value

A name string for the key. You are responsible for releasing this string.

Discussion

Given a virtual key code, returns a description as a CFStringRef. This will either be the character generated by the corresponding key in the current keyboard layout (for instance, A) or a string loaded from the current string table (for instance, Caps Lock or ).

Only avaliable if KEYNAMING_ENABLE_VKC is non-zero.


KeyNamingCopyKeyNames


Get names for a list of keys.

CFStringRef KeyNamingCopyKeyNames(
    uint32_t inCount,
    const uint16_t *const inVirtualKeyCodes);  
Parameters
inCount
The number of keys.
inVirtualKeyCodes
The virtual key codes of the keys to name, in an array.
Return Value

A name string for the keys. You are responsible for releasing this string.

Discussion

Given an array of virtual key codes, return a string containing descriptions of the keys. Key names will be separated by two spaces. (This is potentially useful for combinations, such as Shift  Option  A.) Marginally more efficient than multiple calls to KeyNamingCopyOneKeyName() in that certain internal state can be cached.

Only avaliable if KEYNAMING_ENABLE_VKC is non-zero.


KeyNamingCopyKeyNamesAsArray


Get names for a list of keys, as a CFArray.

CFArrayRef KeyNamingCopyKeyNamesAsArray(
    uint32_t inCount,
    const uint16_t *const inVirtualKeyCodes);  
Parameters
inCount
The number of keys.
inVirtualKeyCodes
The virtual key codes of the keys to name, in an array.
Return Value

A list of name strings for the keys. You are responsible for releasing this array.

Discussion

Given an array of virtual key codes, return a list containing a description of each of the keys. Marginally more efficient than multiple calls to KeyNamingCopyOneKeyName() in that certain internal state can be cached.

Only avaliable if KEYNAMING_ENABLE_VKC is non-zero.


KeyNamingCopyOneKeyNameHID


Get a name for a key.

CFStringRef KeyNamingCopyOneKeyNameHID(
    int32_t inUsage);  
Parameters
inUsage
The HID usage code of the key to name.
Return Value

A name string for the key. You are responsible for releasing this string.

Discussion

Given a HID usage code in the Keyboard or Keypad page, returns a description as a CFStringRef. This will either be the character generated by the corresponding key in the current keyboard layout (for instance, A) or a string loaded from the current string table (for instance, Caps Lock or ).

Only avaliable if KEYNAMING_ENABLE_HID is non-zero.


KeyNamingCopyKeyNamesHID


Get names for a list of keys.

CFStringRef KeyNamingCopyKeyNamesHID(
    uint32_t inCount,
    const int32_t *const inUsages);  
Parameters
inCount
The number of keys.
inUsages
The HID usage codes of the keys to name, in an array.
Return Value

A name string for the keys. You are responsible for releasing this string.

Discussion

Given an array of HID usage codes, return a string containing descriptions of the keys. Key names will be separated by two spaces. (This is potentially useful for combinations, such as Shift  Option  A.) Marginally more efficient than multiple calls to KeyNamingCopyOneKeyNameHID() in that certain internal state can be cached.

Only avaliable if KEYNAMING_ENABLE_HID is non-zero.


KeyNamingCopyKeyNamesAsArrayHID


Get names for a list of keys, as a CFArray.

CFArrayRef KeyNamingCopyKeyNamesAsArrayHID(
    uint32_t inCount,
    const int32_t *const inUsages);  
Parameters
inCount
The number of keys.
inUsages
The HID usage codes of the keys to name, in an array.
Return Value

A list of name strings for the keys. You are responsible for releasing this array.

Discussion

Given an array of HID usage codes, return a list containing a description of each of the keys. Marginally more efficient than multiple calls to KeyNamingCopyOneKeyNameHID() in that certain internal state can be cached.

Only avaliable if KEYNAMING_ENABLE_VKC is non-zero.


KeyNamingSetStringTable


Specifies the string table to use for naming special keys.

void KeyNamingSetStringTable(
    CFStringRef inTableName);  
Parameters
inTableName
The name of the string table to use.
Discussion

Call to identify the property list/.strings file KeyNaming should use for special key names. The default is KeyNaming. Passing NULL will revert to default.


KeyNamingSetStringTableAndBundle


Specifies the string table to use for naming special keys.

void KeyNamingSetStringTableAndBundle(
    CFStringRef inTableName,
    CFBundleRef inBundle);  
Parameters
inTableName
The name of the string table to use.
inBundle
The bundle to look in.
Discussion

Call to identify the property list/.strings file KeyNaming should use for special key names, and the bundle in which to look for the file. The defaults are KeyNaming and NULL, which will cause the main bundle to be used. Passing NULL will revert to default.

© 2001–2008 Jens Ayton Last Updated: 2008-10-22