2007-09-21 23:36:59 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2007-09-21 20:45:47 +00: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;
|
|
|
|
|
|
|
|
|
|
namespace Examples.Tests
|
|
|
|
|
{
|
|
|
|
|
public partial class S04_Input_Logger : Form, IExample
|
|
|
|
|
{
|
|
|
|
|
InputDriver driver;
|
|
|
|
|
Dictionary<IntPtr, ListBox> keyboardListBoxes = new Dictionary<IntPtr, ListBox>(4);
|
2007-09-22 13:13:17 +00:00
|
|
|
|
bool stop_polling;
|
2007-09-21 20:45:47 +00:00
|
|
|
|
|
|
|
|
|
public S04_Input_Logger()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
WindowInfo info = new WindowInfo(this);
|
|
|
|
|
driver = new InputDriver(info);
|
2007-09-22 13:13:17 +00:00
|
|
|
|
Trace.WriteLine(String.Format("Keyboard count: {0}", driver.Keyboard.Count));
|
|
|
|
|
Trace.WriteLine(String.Format("Mouse count: {0}", driver.Mouse.Count));
|
2007-09-21 20:45:47 +00:00
|
|
|
|
|
|
|
|
|
switch (driver.Keyboard.Count)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
Debug.Print("No keyboard present, or keyboard driver failed to load");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[2].DeviceID, listBox3);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[2].DeviceID, listBox3);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[3].DeviceID, listBox4);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Debug.Print("Only the first 4 keyboards will be shown in the keyboard logger.");
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[0].DeviceID, listBox1);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[1].DeviceID, listBox2);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[2].DeviceID, listBox3);
|
|
|
|
|
keyboardListBoxes.Add(driver.Keyboard[3].DeviceID, listBox4);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-21 21:30:18 +00:00
|
|
|
|
// Add available mice to the mouse input logger.
|
2007-09-22 13:13:17 +00:00
|
|
|
|
if (driver.Mouse.Count > 0)
|
2007-09-21 21:30:18 +00:00
|
|
|
|
{
|
2007-09-22 13:13:17 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
foreach (Mouse m in driver.Mouse)
|
|
|
|
|
{
|
|
|
|
|
ChooseMouse.Items.Add(String.Format("Mouse {0} ({1})", ++i, m.Description));
|
|
|
|
|
m.ButtonDown += LogMouseButtonDown;
|
|
|
|
|
m.ButtonUp += LogMouseButtonUp;
|
|
|
|
|
}
|
2007-09-21 21:30:18 +00:00
|
|
|
|
ChooseMouse.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-21 20:45:47 +00:00
|
|
|
|
foreach (OpenTK.Input.Keyboard k in driver.Keyboard)
|
|
|
|
|
{
|
|
|
|
|
k.KeyDown += new KeyDownEvent(LogKeyDown);
|
|
|
|
|
k.KeyUp += new KeyUpEvent(LogKeyUp);
|
|
|
|
|
}
|
2007-09-22 13:13:17 +00:00
|
|
|
|
|
|
|
|
|
//PollTimer.Tick += new EventHandler(PollTimer_Tick);
|
|
|
|
|
//PollTimer.Start();
|
|
|
|
|
Application.Idle += new EventHandler(Application_Idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Application_Idle(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Update mouse coordinates.
|
|
|
|
|
MouseXText.Text = driver.Mouse[ChooseMouse.SelectedIndex].X.ToString();
|
|
|
|
|
MouseYText.Text = driver.Mouse[ChooseMouse.SelectedIndex].Y.ToString();
|
|
|
|
|
MouseDXText.Text = driver.Mouse[ChooseMouse.SelectedIndex].XDelta.ToString();
|
|
|
|
|
MouseDYText.Text = driver.Mouse[ChooseMouse.SelectedIndex].YDelta.ToString();
|
|
|
|
|
MouseWheelText.Text = driver.Mouse[ChooseMouse.SelectedIndex].Wheel.ToString();
|
|
|
|
|
//MouseWheelDelta.Text = driver.Mouse[ChooseMouse.SelectedIndex].WheelDelta.ToString();
|
2007-09-21 20:45:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-21 21:30:18 +00:00
|
|
|
|
void LogMouseButtonDown(IMouse sender, MouseButton button)
|
|
|
|
|
{
|
2007-09-22 13:13:17 +00:00
|
|
|
|
Trace.WriteLine(String.Format("Mouse button down: {0} on device: {1}", button, sender.DeviceID));
|
|
|
|
|
if (sender.DeviceID == driver.Mouse[ChooseMouse.SelectedIndex].DeviceID)
|
|
|
|
|
MouseButtons.Items.Add(button);
|
2007-09-21 21:30:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LogMouseButtonUp(IMouse sender, MouseButton button)
|
|
|
|
|
{
|
2007-09-22 13:13:17 +00:00
|
|
|
|
Trace.WriteLine(String.Format("Mouse button up: {0} on device: {1}", button, sender.DeviceID));
|
|
|
|
|
if (sender.DeviceID == driver.Mouse[ChooseMouse.SelectedIndex].DeviceID)
|
|
|
|
|
MouseButtons.Items.Remove(button);
|
2007-09-21 21:30:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-21 20:45:47 +00:00
|
|
|
|
void LogKeyDown(object sender, Key key)
|
|
|
|
|
{
|
2007-09-22 13:13:17 +00:00
|
|
|
|
Trace.WriteLine(String.Format("Key down: {0} on device: {1}", key, (sender as Keyboard).DeviceID));
|
2007-09-21 20:45:47 +00:00
|
|
|
|
keyboardListBoxes[(sender as Keyboard).DeviceID].Items.Add(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LogKeyUp(object sender, Key key)
|
|
|
|
|
{
|
2007-09-22 13:13:17 +00:00
|
|
|
|
Trace.WriteLine(String.Format("Key up: {0} on device: {1}", key, (sender as Keyboard).DeviceID));
|
2007-09-21 20:45:47 +00:00
|
|
|
|
keyboardListBoxes[(sender as Keyboard).DeviceID].Items.Remove(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IExample Members
|
|
|
|
|
|
|
|
|
|
public void Launch()
|
|
|
|
|
{
|
|
|
|
|
// Empty
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-09-22 13:13:17 +00:00
|
|
|
|
|
|
|
|
|
private void ChooseMouse_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MouseButtons.Items.Clear();
|
|
|
|
|
}
|
2007-09-21 20:45:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|