2007-09-22 01:36:59 +02:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-09-21 22:45:47 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Platform;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
using System.Diagnostics;
|
2007-09-22 16:59:33 +02:00
|
|
|
|
using System.Threading;
|
2007-09-21 22:45:47 +02:00
|
|
|
|
|
|
|
|
|
namespace Examples.Tests
|
|
|
|
|
{
|
2008-01-18 15:01:06 +01:00
|
|
|
|
[Example("Input Logger", ExampleCategory.Test)]
|
2008-01-04 21:55:15 +01:00
|
|
|
|
public partial class S04_Input_Logger : Form
|
2007-09-21 22:45:47 +02:00
|
|
|
|
{
|
2007-09-26 13:47:30 +02:00
|
|
|
|
Thread thread;
|
|
|
|
|
GameWindow hidden;
|
|
|
|
|
bool start;
|
2007-09-21 22:45:47 +02:00
|
|
|
|
Dictionary<IntPtr, ListBox> keyboardListBoxes = new Dictionary<IntPtr, ListBox>(4);
|
|
|
|
|
|
|
|
|
|
public S04_Input_Logger()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2007-09-26 13:47:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LaunchGameWindow()
|
|
|
|
|
{
|
2008-02-28 14:57:48 +01:00
|
|
|
|
hidden = new GameWindow("OpenTK | Hidden input window", 16, 16);
|
2007-09-26 13:47:30 +02:00
|
|
|
|
hidden.Load += hidden_Load;
|
2008-01-06 03:18:58 +01:00
|
|
|
|
hidden.Unload += hidden_Unload;
|
2007-09-26 13:47:30 +02:00
|
|
|
|
hidden.Run(60.0, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-06 03:18:58 +01:00
|
|
|
|
void hidden_Load(GameWindow sender, EventArgs e)
|
2007-09-26 13:47:30 +02:00
|
|
|
|
{
|
|
|
|
|
start = true;
|
2007-09-21 22:45:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-06 03:18:58 +01:00
|
|
|
|
void hidden_Unload(GameWindow sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.BeginInvoke(on_hidden_unload, sender, e, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delegate void CloseTrigger(GameWindow sender, EventArgs e, Form f);
|
|
|
|
|
CloseTrigger on_hidden_unload = delegate(GameWindow sender, EventArgs e, Form f) { f.Close(); };
|
2008-01-04 21:55:15 +01:00
|
|
|
|
|
2007-09-21 22:45:47 +02:00
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
2008-01-04 21:55:15 +01:00
|
|
|
|
thread = new Thread(LaunchGameWindow);
|
|
|
|
|
thread.Start();
|
|
|
|
|
|
2007-09-26 13:47:30 +02:00
|
|
|
|
while (!start)
|
|
|
|
|
Thread.Sleep(100);
|
2007-09-21 22:45:47 +02:00
|
|
|
|
|
2008-02-28 14:57:48 +01:00
|
|
|
|
//WindowInfo info = new WindowInfo(this);
|
2007-09-26 13:47:30 +02:00
|
|
|
|
|
|
|
|
|
keyboardListBoxes.Add(hidden.Keyboard.DeviceID, listBox1);
|
|
|
|
|
|
2007-09-21 23:30:18 +02:00
|
|
|
|
// Add available mice to the mouse input logger.
|
2007-09-26 13:47:30 +02:00
|
|
|
|
ChooseMouse.Items.Add(String.Format("Mouse {0} ({1})", 0, hidden.Mouse.Description));
|
|
|
|
|
hidden.Mouse.ButtonDown += LogMouseButtonDown;
|
|
|
|
|
hidden.Mouse.ButtonUp += LogMouseButtonUp;
|
2007-09-21 23:30:18 +02:00
|
|
|
|
|
2007-09-26 13:47:30 +02:00
|
|
|
|
hidden.Keyboard.KeyDown += LogKeyDown;
|
|
|
|
|
hidden.Keyboard.KeyUp += LogKeyUp;
|
|
|
|
|
|
|
|
|
|
//Application.Idle += new EventHandler(UpdateDevices);
|
|
|
|
|
hidden.UpdateFrame += hidden_UpdateFrame;
|
2008-01-04 21:55:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnClosing(e);
|
2007-09-22 15:13:17 +02:00
|
|
|
|
|
2008-02-28 14:57:48 +01:00
|
|
|
|
hidden.ExitAsync();
|
|
|
|
|
|
2008-01-04 21:55:15 +01:00
|
|
|
|
while (hidden.Exists)
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
|
|
|
|
|
e.Cancel = false;
|
2007-09-22 15:13:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-04 21:55:15 +01:00
|
|
|
|
delegate void ControlLogMouseKey(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button);
|
2008-01-06 03:18:58 +01:00
|
|
|
|
ControlLogMouseKey ControlLogMouseKeyDown =
|
2008-01-04 21:55:15 +01:00
|
|
|
|
delegate(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button)
|
|
|
|
|
{
|
|
|
|
|
if (sender.DeviceID == input_window.Mouse.DeviceID)
|
2008-01-06 11:56:10 +01:00
|
|
|
|
control.MouseButtonsBox.Items.Add(button);
|
2008-01-06 03:18:58 +01:00
|
|
|
|
};
|
|
|
|
|
ControlLogMouseKey ControlLogMouseKeyUp =
|
2008-01-04 21:55:15 +01:00
|
|
|
|
delegate(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button)
|
|
|
|
|
{
|
|
|
|
|
if (sender.DeviceID == input_window.Mouse.DeviceID)
|
2008-01-06 11:56:10 +01:00
|
|
|
|
control.MouseButtonsBox.Items.Remove(button);
|
2008-01-06 03:18:58 +01:00
|
|
|
|
};
|
2008-01-04 21:55:15 +01:00
|
|
|
|
|
|
|
|
|
delegate void ControlLogMousePosition(GameWindow input_window, S04_Input_Logger control);
|
2008-01-06 03:18:58 +01:00
|
|
|
|
ControlLogMousePosition ControlLogMousePositionChanges =
|
2008-01-04 21:55:15 +01:00
|
|
|
|
delegate(GameWindow input_window, S04_Input_Logger control)
|
|
|
|
|
{
|
|
|
|
|
// Update mouse coordinates.
|
|
|
|
|
control.MouseXText.Text = input_window.Mouse.X.ToString();
|
|
|
|
|
control.MouseYText.Text = input_window.Mouse.Y.ToString();
|
|
|
|
|
control.MouseDXText.Text = input_window.Mouse.XDelta.ToString();
|
|
|
|
|
control.MouseDYText.Text = input_window.Mouse.YDelta.ToString();
|
|
|
|
|
control.MouseWheelText.Text = input_window.Mouse.Wheel.ToString();
|
2008-01-06 03:18:58 +01:00
|
|
|
|
//System.Drawing.Point p = input_window.PointToClient(input_window.Mouse.Position);
|
|
|
|
|
//System.Drawing.Point p = control.PointToClient(input_window.Mouse.Position);
|
|
|
|
|
//control.MouseXWindow.Text = p.X.ToString();
|
|
|
|
|
//control.MouseYWindow.Text = p.Y.ToString();
|
2008-01-04 21:55:15 +01:00
|
|
|
|
//MouseWheelDelta.Text = driver.Mouse[ChooseMouse.SelectedIndex].WheelDelta.ToString();
|
2008-01-06 03:18:58 +01:00
|
|
|
|
};
|
2008-01-04 21:55:15 +01:00
|
|
|
|
|
2008-01-06 11:56:10 +01:00
|
|
|
|
delegate void ControlLogKeyboard(GameWindow input_window, S04_Input_Logger control, OpenTK.Input.KeyboardDevice sender, Key key);
|
2008-01-06 03:18:58 +01:00
|
|
|
|
ControlLogKeyboard ControlLogKeyboardDown =
|
2008-01-04 21:55:15 +01:00
|
|
|
|
delegate(GameWindow input_window, S04_Input_Logger control, KeyboardDevice sender, Key key)
|
|
|
|
|
{
|
2008-01-15 10:51:32 +01:00
|
|
|
|
control.keyboardListBoxes[sender.DeviceID].Items.Add(key);
|
2008-01-06 03:18:58 +01:00
|
|
|
|
};
|
|
|
|
|
ControlLogKeyboard ControlLogKeyboardUp =
|
2008-01-04 21:55:15 +01:00
|
|
|
|
delegate(GameWindow input_window, S04_Input_Logger control, KeyboardDevice sender, Key key)
|
|
|
|
|
{
|
2008-01-15 10:51:32 +01:00
|
|
|
|
control.keyboardListBoxes[sender.DeviceID].Items.Remove(key);
|
2008-01-06 03:18:58 +01:00
|
|
|
|
};
|
2008-01-04 21:55:15 +01:00
|
|
|
|
|
2007-09-26 13:47:30 +02:00
|
|
|
|
void hidden_UpdateFrame(object sender, UpdateFrameEventArgs e)
|
2007-09-22 15:13:17 +02:00
|
|
|
|
{
|
2008-01-04 21:55:15 +01:00
|
|
|
|
this.BeginInvoke(ControlLogMousePositionChanges, hidden, this);
|
2007-09-21 22:45:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 13:47:30 +02:00
|
|
|
|
void LogMouseButtonDown(MouseDevice sender, MouseButton button)
|
2007-09-21 23:30:18 +02:00
|
|
|
|
{
|
2008-01-04 21:55:15 +01:00
|
|
|
|
this.BeginInvoke(ControlLogMouseKeyDown, hidden, this, sender, button);
|
2007-09-21 23:30:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 13:47:30 +02:00
|
|
|
|
void LogMouseButtonUp(MouseDevice sender, MouseButton button)
|
2007-09-21 23:30:18 +02:00
|
|
|
|
{
|
2008-01-04 21:55:15 +01:00
|
|
|
|
this.BeginInvoke(ControlLogMouseKeyUp, hidden, this, sender, button);
|
2007-09-21 23:30:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 13:47:30 +02:00
|
|
|
|
void LogKeyDown(KeyboardDevice sender, Key key)
|
2007-09-21 22:45:47 +02:00
|
|
|
|
{
|
2008-01-04 21:55:15 +01:00
|
|
|
|
this.BeginInvoke(ControlLogKeyboardDown, hidden, this, sender, key);
|
2007-09-21 22:45:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 13:47:30 +02:00
|
|
|
|
void LogKeyUp(KeyboardDevice sender, Key key)
|
2007-09-21 22:45:47 +02:00
|
|
|
|
{
|
2008-01-04 21:55:15 +01:00
|
|
|
|
this.BeginInvoke(ControlLogKeyboardUp, hidden, this, sender, key);
|
2007-09-21 22:45:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-04 21:55:15 +01:00
|
|
|
|
private void ChooseMouse_SelectedIndexChanged(object sender, EventArgs e)
|
2007-09-21 22:45:47 +02:00
|
|
|
|
{
|
2008-01-06 11:56:10 +01:00
|
|
|
|
MouseButtonsBox.Items.Clear();
|
2007-09-21 22:45:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-04 21:55:15 +01:00
|
|
|
|
#region public static void Main()
|
2007-10-20 12:54:40 +02:00
|
|
|
|
|
2008-01-04 21:55:15 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entry point of this example.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main()
|
2007-09-22 15:13:17 +02:00
|
|
|
|
{
|
2008-01-04 21:55:15 +01:00
|
|
|
|
using (S04_Input_Logger example = new S04_Input_Logger())
|
|
|
|
|
{
|
|
|
|
|
// Get the title and category of this example using reflection.
|
|
|
|
|
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
|
|
|
|
example.Text = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
|
|
|
|
example.ShowDialog();
|
|
|
|
|
}
|
2007-09-22 15:13:17 +02:00
|
|
|
|
}
|
2008-01-04 21:55:15 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
2007-09-21 22:45:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|