1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
6<META name="GENERATOR" content="Microsoft FrontPage 5.0">
7<META http-equiv="Content-Style-Type" content="text/css">
8<LINK rel="stylesheet" type="text/css" href="../CSS/revolution.css">
9<title>KBDKeyEvent structure</title>
10</head>
11
12<body>
13
14<h1>KBDKeyEvent structure</h1>
15
16<h2>Syntax</h2>
17<dl><dd><pre class="construction">
18#include &lt;revolution/kbd/kbd.h&gt;
19
20typedef struct _KBDKeyEvent {
21  KBDChannel channel;
22  KBDHIDCode  hid;        // USB HID code
23  u8          mode;       // for up/down/etc
24  KBDModState modState;   // modifier state
25  KBDUnicode  unicode;    // Unicode, if any
26} KBDKeyEvent;
27</pre></dd></dl>
28
29<H2>Description</H2>
30<p>
31The <code>KBDKeyEvent</code> structure contains the keyboard channel that generated the event, the USB HID code associated with the key, the type of key event (see below), the current keyboard modifier state, and the translated Unicode associated with the key.</p>
32<p>
33An application function, if registered with <a href="KBDSetKeyCallback.html"><code>KBDSetKeyCallback</code></a>, is called with a pointer to this structure. This structure is also returned with a call to <a href="KBDGetKey.html"><code>KBDGetKey</code></a>.
34</p>
35<p>For more information on HID codes and Unicodes, refer to the <a href="intro.html#KBDUnicode">Introduction</a>.</p>
36<p>The key mode contains a bit vector that indicates whether the key event was a press or release, and whether the event was an initial key press or a repeat key event.</p>
37<p>The following macros can be used in a boolean expression to query the state of key event mode.</p>
38
39<dl><dd><pre class="construction">
40#define KBD_KEY_MODE_UP(_key_mode)     (!((_key_mode) &amp; KBD_KM_DOWN))
41#define KBD_KEY_MODE_DOWN(_key_mode)   ((_key_mode) &amp; KBD_KM_DOWN)
42#define KBD_KEY_MODE_REPEAT(_key_mode) ((_key_mode) &amp; KBD_KM_REPEAT)
43</pre></dd></dl>
44
45<p>The <SPAN class="argument">modState</SPAN> contained in the key event is a status maintained by the KBD driver as to which modifiers are active. However, do not confuse this with the status of which keyboard modifier keys are actually being pressed. These two may differ. For instance, if the sticky bit state of the keyboard is enabled (see <a href="KBDSetAccessSticky.html"><code>KBDSetAccessSticky</code></a>), the keyboard modifier keys become toggle buttons and their state of being up or down is no longer consistent with whether or not the corresponding modifier bit is set.</p>
46<p>The following macros can be used to help classify the output Unicode.</p>
47
48<dl><dd><pre class="construction">
49#define KBD_UC_IS_PRIVATE(uc) (((uc)&gt;=0xf000 &amp;&amp; (uc)&lt;=0xF1FF) || ((uc)==0xFFFF))
50</pre></dd></dl>
51
52<p>The above macro indicates whether the Unicode value is private to the KBD library.(?(For more information, see the <a href="intro.html#KBDUnicode">Introduction</a>.) ) If the value returned by the KBD library is not private, then it is an ASCII/Unicode printing character.</p>
53
54<dl><dd><pre class="construction">
55#define KBD_UC_IS_MODIFIER(uc) ((uc)&gt;=0xf000 &amp;&amp; (uc)&lt;=0xf01f)
56</pre></dd></dl>
57
58<p>This indicates whether a value represents a modifier key (for example, <code>KBK_Shift</code> and <code>KBK_Num_Lock</code>).</p>
59
60<dl><dd><pre class="construction">
61#define KBD_UC_IS_KP_REG_KEY(uc) (((uc)&gt;=0xf100) &amp;&amp; ((uc)&lt;=0xf13f))
62#define KBD_KP_REG_KEY_TO_ASCII(uc) ((uc)&amp;0x3f)
63</pre></dd></dl>
64
65<p>The first macro indicates whether the Unicode value represents a numeric keypad key that has a regular ASCII/Unicode definition. If so, the second macro will convert the private keypad Unicode value into its regular ASCII/Unicode value. (For example, <code>KBK_Keypad_Asterisk</code>&nbsp;=&nbsp;<code>0xf12A</code> is converted to &quot;<code>*</code>&quot; = <code>0x2A</code>.)</p>
66
67<dl><dd><pre class="construction">
68#define KBD_UC_IS_KP_NUM_NL_KEY(uc) (((uc)&gt;=KBK_Keypad_0 &amp;&amp; ((uc)&lt;=KBK_Keypad_9)))
69#define KBD_UC_IS_KP_NUM_UL_KEY(uc) (((uc)&gt;=KBK_Keypad_Insert &amp;&amp; ((uc)&lt;=KBK_Keypad_Page_Up)))
70#define KBD_KP_NUM_UL_KEY_TO_KP_NUM_NL_KEY(uc) ((KBDUnicode)((uc)-0x40))
71</pre></dd></dl>
72
73<p>These macros indicate whether a value is a keypad digit key with Num Lock on (first) or off (second). The third macro converts the second type of a value to the first.</p>
74
75<dl><dd><pre class="construction">
76#define KBD_UC_IS_CTRL_KEY  (((uc)&gt;=0xf1c0) &amp;&amp; ((uc)&lt;=0xf1df))
77#define KBD_CTRL_KEY_TO_ASCII(uc) ((uc)&amp;0x1f)
78</pre></dd></dl>
79
80<p>The first macro indicates whether a value is a control key (Backspace, Tab, Enter, or Escape), and the second converts the private value to a regular ASCII/Unicode value.</p>
81<p>If an application requires only the information about raw key presses and releases, it can filter out repeat and pseudo key events using the macros above. Repeat can also be disabled altogether using <a href="KBDSetRepeat.html"><code>KBDSetRepeat</code></a>.</p>
82<p>Similarly, if an application wishes to know only about processed Unicode output, it can filter out key-up events and modifier-key presses using the macros above.</p>
83
84<h2>See Also</h2>
85<P class="reference">
86<a href="list.html">Keyboard Functions</a>,
87<a href="KBDSetKeyCallback.html">KBDSetKeyCallback</a>,
88<a href="KBDGetKey.html">KBDGetKey</a>
89</p>
90
91<H2>Revision History</H2>
92<p>
932007/03/27 Added <CODE>KBDHIDCode</CODE> type.<br>2007/03/20 Initial version.<br>
94</p>
95
96<hr><p>CONFIDENTIAL</p></body>
97</HTML>