2007-07-27 01:37:12 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Using directives ---
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
2007-08-04 12:09:58 +00:00
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
2007-07-27 01:37:12 +00:00
|
|
|
|
#endregion
|
2007-07-26 22:56:55 +00:00
|
|
|
|
|
|
|
|
|
namespace OpenTK.Input
|
|
|
|
|
{
|
|
|
|
|
public class Keyboard : IKeyboard
|
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
//private IKeyboard keyboard;
|
2007-08-05 16:04:39 +00:00
|
|
|
|
private bool[] keys = new bool[(int)Key.MaxKeys];
|
2007-08-04 12:09:58 +00:00
|
|
|
|
private string description;
|
|
|
|
|
private int numKeys, numFKeys, numLeds;
|
|
|
|
|
private long devID;
|
2007-07-26 22:56:55 +00:00
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
#region --- Constructors ---
|
|
|
|
|
|
2007-07-26 22:56:55 +00:00
|
|
|
|
public Keyboard()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-03 00:14:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-07-27 01:20:55 +00:00
|
|
|
|
#region --- IKeyboard members ---
|
|
|
|
|
|
2007-08-05 16:04:39 +00:00
|
|
|
|
public bool this[Key k]
|
2007-07-26 22:56:55 +00:00
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
get { return keys[(int)k]; }
|
|
|
|
|
internal set
|
|
|
|
|
{
|
|
|
|
|
Debug.Print("OpenTK key {0} {1}.", k, value ? "pressed" : "released");
|
|
|
|
|
keys[(int)k] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int NumberOfKeys
|
|
|
|
|
{
|
|
|
|
|
get { return numKeys; }
|
|
|
|
|
internal set { numKeys = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int NumberOfFunctionKeys
|
|
|
|
|
{
|
|
|
|
|
get { return numFKeys; }
|
|
|
|
|
internal set { numFKeys = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int NumberOfLeds
|
|
|
|
|
{
|
|
|
|
|
get { return numLeds; }
|
|
|
|
|
internal set { numLeds = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Device dependent ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public long DeviceID
|
|
|
|
|
{
|
|
|
|
|
get { return devID; }
|
|
|
|
|
internal set { devID = value; }
|
2007-07-26 22:56:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-27 01:20:55 +00:00
|
|
|
|
#endregion
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
#region --- IInputDevice Members ---
|
|
|
|
|
|
|
|
|
|
public string Description
|
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
get { return description; }
|
|
|
|
|
internal set { description = value; }
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InputDeviceType DeviceType
|
|
|
|
|
{
|
2007-08-04 12:09:58 +00:00
|
|
|
|
get { return InputDeviceType.Keyboard; }
|
2007-08-03 00:14:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-08-04 12:09:58 +00:00
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
//return base.GetHashCode();
|
|
|
|
|
return (int)(numKeys ^ numFKeys ^ numLeds ^ devID.GetHashCode() ^ description.GetHashCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
//return base.ToString();
|
|
|
|
|
return String.Format("Keyboard: '{0}', {1} keys, {2} function keys, {3} leds. Device ID: {4}",
|
|
|
|
|
description, NumberOfKeys, NumberOfFunctionKeys, NumberOfLeds, DeviceID);
|
|
|
|
|
}
|
2007-07-26 22:56:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-05 16:04:39 +00:00
|
|
|
|
#region public enum Key : int
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The available keyboard keys.
|
|
|
|
|
/// </summary>
|
2007-08-05 16:04:39 +00:00
|
|
|
|
public enum Key : int
|
2007-07-26 22:56:55 +00:00
|
|
|
|
{
|
|
|
|
|
// Modifiers
|
2007-08-05 16:04:39 +00:00
|
|
|
|
ShiftLeft = 0,
|
|
|
|
|
ShiftRight,
|
|
|
|
|
ControlLeft,
|
|
|
|
|
ControlRight,
|
|
|
|
|
AltLeft,
|
|
|
|
|
AltRight,
|
|
|
|
|
WinLeft,
|
|
|
|
|
WinRight,
|
2007-08-03 00:14:31 +00:00
|
|
|
|
Menu,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
|
|
|
|
|
// Function keys (hopefully enough for most keyboards - mine has 26)
|
2007-08-05 16:04:39 +00:00
|
|
|
|
// <keysymdef.h> on X11 reports up to 35 function keys.
|
2007-07-26 22:56:55 +00:00
|
|
|
|
F1, F2, F3, F4,
|
|
|
|
|
F5, F6, F7, F8,
|
|
|
|
|
F9, F10, F11, F12,
|
|
|
|
|
F13, F14, F15, F16,
|
|
|
|
|
F17, F18, F19, F20,
|
|
|
|
|
F21, F22, F23, F24,
|
|
|
|
|
F25, F26, F27, F28,
|
|
|
|
|
F29, F30, F31, F32,
|
2007-08-05 16:04:39 +00:00
|
|
|
|
F33, F34, F35,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
|
|
|
|
|
// Direction arrows
|
|
|
|
|
Up,
|
|
|
|
|
Down,
|
|
|
|
|
Left,
|
|
|
|
|
Right,
|
|
|
|
|
|
|
|
|
|
Enter,
|
|
|
|
|
Escape,
|
|
|
|
|
Space,
|
|
|
|
|
Tab,
|
2007-08-06 09:22:04 +00:00
|
|
|
|
BackSpace,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
Insert,
|
|
|
|
|
Delete,
|
|
|
|
|
PageUp,
|
|
|
|
|
PageDown,
|
|
|
|
|
Home,
|
|
|
|
|
End,
|
|
|
|
|
CapsLock,
|
2007-08-03 00:14:31 +00:00
|
|
|
|
PrintScreen,
|
|
|
|
|
Pause,
|
|
|
|
|
NumLock,
|
|
|
|
|
|
|
|
|
|
// Special keys
|
|
|
|
|
Sleep,
|
|
|
|
|
/*LogOff,
|
|
|
|
|
Help,
|
|
|
|
|
Undo,
|
|
|
|
|
Redo,
|
|
|
|
|
New,
|
|
|
|
|
Open,
|
|
|
|
|
Close,
|
|
|
|
|
Reply,
|
|
|
|
|
Forward,
|
|
|
|
|
Send,
|
|
|
|
|
Spell,
|
|
|
|
|
Save,
|
|
|
|
|
Calculator,
|
|
|
|
|
|
|
|
|
|
// Folders and applications
|
|
|
|
|
Documents,
|
|
|
|
|
Pictures,
|
|
|
|
|
Music,
|
|
|
|
|
MediaPlayer,
|
|
|
|
|
Mail,
|
|
|
|
|
Browser,
|
|
|
|
|
Messenger,
|
|
|
|
|
|
|
|
|
|
// Multimedia keys
|
|
|
|
|
Mute,
|
|
|
|
|
PlayPause,
|
|
|
|
|
Stop,
|
|
|
|
|
VolumeUp,
|
|
|
|
|
VOlumeDown,
|
|
|
|
|
PreviousTrack,
|
|
|
|
|
NextTrack,*/
|
2007-07-26 22:56:55 +00:00
|
|
|
|
|
|
|
|
|
// Keypad keys
|
|
|
|
|
Keypad0,
|
|
|
|
|
Keypad1,
|
|
|
|
|
Keypad2,
|
|
|
|
|
Keypad3,
|
|
|
|
|
Keypad4,
|
|
|
|
|
Keypad5,
|
|
|
|
|
Keypad6,
|
|
|
|
|
Keypad7,
|
|
|
|
|
Keypad8,
|
|
|
|
|
Keypad9,
|
|
|
|
|
KeypadDivide,
|
|
|
|
|
KeypadMultiply,
|
|
|
|
|
KeypadSubtract,
|
|
|
|
|
KeypadAdd,
|
|
|
|
|
KeypadDecimal,
|
2007-08-03 00:14:31 +00:00
|
|
|
|
//KeypadEnter,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
|
|
|
|
|
// Letters
|
|
|
|
|
A, B, C, D, E, F, G,
|
|
|
|
|
H, I, J, K, L, M, N,
|
|
|
|
|
O, P, Q, R, S, T, U,
|
|
|
|
|
V, W, X, Y, Z,
|
|
|
|
|
|
|
|
|
|
// Numbers
|
|
|
|
|
Number0,
|
|
|
|
|
Number1,
|
|
|
|
|
Number2,
|
|
|
|
|
Number3,
|
|
|
|
|
Number4,
|
|
|
|
|
Number5,
|
|
|
|
|
Number6,
|
|
|
|
|
Number7,
|
|
|
|
|
Number8,
|
|
|
|
|
Number9,
|
|
|
|
|
|
|
|
|
|
// Symbols
|
2007-08-03 00:14:31 +00:00
|
|
|
|
Tilde,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
Minus,
|
2007-08-03 00:14:31 +00:00
|
|
|
|
//Equal,
|
|
|
|
|
Plus,
|
2007-08-06 00:08:51 +00:00
|
|
|
|
BracketLeft,
|
|
|
|
|
BracketRight,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
Semicolon,
|
2007-08-03 00:14:31 +00:00
|
|
|
|
Quote,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
Comma,
|
2007-08-03 00:14:31 +00:00
|
|
|
|
Period,
|
2007-07-26 22:56:55 +00:00
|
|
|
|
Slash,
|
|
|
|
|
BackSlash,
|
|
|
|
|
|
|
|
|
|
MaxKeys
|
|
|
|
|
}
|
2007-08-03 00:14:31 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|