Difference between revisions of "Keyboard (Chili Framework)"

From Chilipedia
Jump to: navigation, search
(Event)
Line 1: Line 1:
 
With <code>Keyboard</code>, you can get the current state of depressed keys, and you can pop key press and release events out of an <code>Event</code> queue contained in <code>Keyboard</code>. You can also turn autorepeat on/off. Whopee. (''Note: the ''<code>kbd</code>'' object lives in ''<code>MainWindow</code>'''s belly.'')
 
With <code>Keyboard</code>, you can get the current state of depressed keys, and you can pop key press and release events out of an <code>Event</code> queue contained in <code>Keyboard</code>. You can also turn autorepeat on/off. Whopee. (''Note: the ''<code>kbd</code>'' object lives in ''<code>MainWindow</code>'''s belly.'')
 +
 +
== Members ==
 +
=== KeyIsPressed ===
 +
<code>bool Keyboard::KeyIsPressed( unsigned char keycode ) const</code><br />
 +
Checks to see if a specific key is currently in the pressed state. The function parameter is the virtual key code of the key that you want to check.
 +
 +
=== ReadKey ===
 +
<code>Event Keyboard::ReadKey()</code><br />
 +
Pull a fresh Event object out of the key press/release event queue. Erases an event from the queue and returns a copy if there is a key press event in the queue. Returns an invalid Event object if the queue is empty.
 +
 +
=== KeyIsEmpty ===
 +
<code>bool Keyboard::KeyIsEmpty() const</code><br />
 +
Check to see if the key event queue is empty.
  
 
== Event ==
 
== Event ==
 
<code>class Keyboard::Event</code><br />
 
<code>class Keyboard::Event</code><br />
  
Key press and release events are held in a buffer in the order they occurred. These events are modeled with their own class because they're precious fucking little snowflakes. You pull them out of the buffer with <code>Keyboard::ReadKey()</code>.
+
Key press and release events are held in a queue in <code>Keyboard</code> in the order they occurred. These events are modeled with their own class because they're precious fucking little snowflakes. You pull them out of the buffer with <code>Keyboard::ReadKey()</code>.
  
 
=== Type ===
 
=== Type ===
Line 29: Line 42:
 
<code>char Keyboard::GetCode()</code><br />
 
<code>char Keyboard::GetCode()</code><br />
  
Gets the virtual key code of the key associated with the <code>Event</code> object. The virtual key code for a standard alphanumeric key is just the <code>char</code> literal (capital if alphabetic), e.g. <code>'A'</code> or <code>'9'</code>. Virtual key codes for other keys are defined with <code>#define</code> macros somewhere in <code>Windows.h</code> (or more likely in one of the headers that it includes). Some common ones are:
+
Gets the virtual key code of the key associated with the <code>Event</code> object.
 +
 
 +
== Virtual Key Codes ==
 +
The virtual key code for a standard alphanumeric key is just the <code>char</code> literal (capital if alphabetic), e.g. <code>'A'</code> or <code>'9'</code>. Virtual key codes for other keys are defined with <code>#define</code> macros somewhere in <code>Windows.h</code> (or more likely in one of the headers that it includes). Some common ones are:
 
* <code>VK_SPACE</code>
 
* <code>VK_SPACE</code>
 
* <code>VK_SHIFT</code>
 
* <code>VK_SHIFT</code>
 
* <code>VK_ENTER</code>
 
* <code>VK_ENTER</code>
 
* <code>VK_ESCAPE</code>
 
* <code>VK_ESCAPE</code>
 
== Members ==
 
 
  
 
== See also ==
 
== See also ==
 
* The [[Chili Framework]]
 
* The [[Chili Framework]]

Revision as of 20:34, 13 July 2016

With Keyboard, you can get the current state of depressed keys, and you can pop key press and release events out of an Event queue contained in Keyboard. You can also turn autorepeat on/off. Whopee. (Note: the kbd object lives in MainWindow's belly.)

Members

KeyIsPressed

bool Keyboard::KeyIsPressed( unsigned char keycode ) const
Checks to see if a specific key is currently in the pressed state. The function parameter is the virtual key code of the key that you want to check.

ReadKey

Event Keyboard::ReadKey()
Pull a fresh Event object out of the key press/release event queue. Erases an event from the queue and returns a copy if there is a key press event in the queue. Returns an invalid Event object if the queue is empty.

KeyIsEmpty

bool Keyboard::KeyIsEmpty() const
Check to see if the key event queue is empty.

Event

class Keyboard::Event

Key press and release events are held in a queue in Keyboard in the order they occurred. These events are modeled with their own class because they're precious fucking little snowflakes. You pull them out of the buffer with Keyboard::ReadKey().

Type

enum Keyboard::Event::Type

This represents the different types of events that can be recorded. The options are Press, Release, and Invalid.

IsPress

bool Keyboard::IsPress() const

Returns true if the event is a press event.

IsRelease

bool Keyboard::IsRelease() const

Returns true if the event is a release event.

IsValid

bool Keyboard::IsValid() const

Returns true if the event is a valid event (reading from an empty buffer will return an invalid event object).

GetCode

char Keyboard::GetCode()

Gets the virtual key code of the key associated with the Event object.

Virtual Key Codes

The virtual key code for a standard alphanumeric key is just the char literal (capital if alphabetic), e.g. 'A' or '9'. Virtual key codes for other keys are defined with #define macros somewhere in Windows.h (or more likely in one of the headers that it includes). Some common ones are:

  • VK_SPACE
  • VK_SHIFT
  • VK_ENTER
  • VK_ESCAPE

See also