Added KeyDown and KeyUp events.

This commit is contained in:
the_fiddler 2010-11-08 21:48:00 +00:00
parent f99d6a2c1c
commit c96a632bab
2 changed files with 60 additions and 3 deletions

View file

@ -229,10 +229,20 @@ namespace OpenTK
/// </summary>
event EventHandler<EventArgs> WindowStateChanged;
/// <summary>
/// Occurs whenever a keybord key is pressed.
/// </summary>
event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyDown;
/// <summary>
/// Occurs whenever a character is typed.
/// </summary>
event EventHandler<KeyPressEventArgs> KeyPress;
/// <summary>
/// Occurs whenever a keyboard key is released.
/// </summary>
event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyUp;
/// <summary>
/// Occurs whenever the mouse cursor leaves the window <see cref="Bounds"/>.
@ -251,9 +261,6 @@ namespace OpenTK
//event EventHandler<MouseEventArgs> MouseClick;
//event EventHandler<MouseEventArgs> MouseDoubleClick;
//event EventHandler<KeyEventArgs> KeyDown;
//event EventHandler<KeyEventArgs> KeyUp;
//event EventHandler<DragEventArgs> DragDrop;
//event EventHandler<DragEventArgs> DragEnter;
//event EventHandler<DragEventArgs> DragOver;

View file

@ -50,6 +50,7 @@ namespace OpenTK
private bool disposed, events;
private bool cursor_visible = true;
private bool previous_cursor_visible = true;
#endregion
@ -588,11 +589,21 @@ namespace OpenTK
/// </summary>
public event EventHandler<EventArgs> IconChanged = delegate { };
/// <summary>
/// Occurs whenever a keybord key is pressed.
/// </summary>
public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyDown = delegate { };
/// <summary>
/// Occurs whenever a character is typed.
/// </summary>
public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
/// <summary>
/// Occurs whenever a keyboard key is released.
/// </summary>
public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyUp = delegate { };
/// <summary>
/// Occurs whenever the window is moved.
/// </summary>
@ -746,6 +757,20 @@ namespace OpenTK
/// <param name="e">Not used.</param>
protected virtual void OnFocusedChanged(EventArgs e)
{
if (!Focused)
{
// Release cursor when losing focus, to ensure
// IDEs continue working as expected.
previous_cursor_visible = CursorVisible;
CursorVisible = true;
}
else if (!previous_cursor_visible)
{
// Make cursor invisible when focus is regained
// if cursor was invisible on previous focus loss.
previous_cursor_visible = true;
CursorVisible = false;
}
FocusedChanged(this, e);
}
@ -764,6 +789,18 @@ namespace OpenTK
#endregion
#region OnKeyDown
/// <summary>
/// Occurs whenever a keybord key is pressed.
/// </summary>
protected virtual void OnKeyDown(KeyboardKeyEventArgs e)
{
KeyDown(this, e);
}
#endregion
#region OnKeyPress
/// <summary>
@ -777,6 +814,19 @@ namespace OpenTK
#endregion
#region OnKeyUp
/// <summary>
/// Called when a keybord key is released.
/// </summary>
/// <param name="e">The <see cref="OpenTK.KeyboardKeyEventArgs"/> for this event.</param>
protected virtual void OnKeyUp(KeyboardKeyEventArgs e)
{
KeyUp(this, e);
}
#endregion
#region OnMove
/// <summary>