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;
|
2007-09-22 14:59:33 +00:00
|
|
|
|
using System.Threading;
|
2007-09-21 20:45:47 +00:00
|
|
|
|
|
|
|
|
|
namespace Examples.Tests
|
|
|
|
|
{
|
2007-09-25 15:47:39 +00:00
|
|
|
|
public partial class S04_Input_Logger : Form//, IExample
|
2007-09-21 20:45:47 +00:00
|
|
|
|
{
|
2007-09-26 11:47:30 +00:00
|
|
|
|
Thread thread;
|
|
|
|
|
GameWindow hidden;
|
|
|
|
|
bool start;
|
2007-09-21 20:45:47 +00:00
|
|
|
|
Dictionary<IntPtr, ListBox> keyboardListBoxes = new Dictionary<IntPtr, ListBox>(4);
|
|
|
|
|
|
|
|
|
|
public S04_Input_Logger()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2007-09-26 11:47:30 +00:00
|
|
|
|
|
|
|
|
|
thread = new Thread(LaunchGameWindow);
|
|
|
|
|
thread.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LaunchGameWindow()
|
|
|
|
|
{
|
2007-10-20 10:54:40 +00:00
|
|
|
|
hidden = new GameWindow(new DisplayMode(30, 30), "OpenTK | Hidden input window");
|
2007-09-26 11:47:30 +00:00
|
|
|
|
hidden.Load += hidden_Load;
|
|
|
|
|
hidden.Run(60.0, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void hidden_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
start = true;
|
2007-09-21 20:45:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
while (!start)
|
2007-09-21 20:45:47 +00:00
|
|
|
|
{
|
2007-09-26 11:47:30 +00:00
|
|
|
|
Thread.Sleep(100);
|
2007-09-21 20:45:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
WindowInfo info = new WindowInfo(this);
|
|
|
|
|
|
|
|
|
|
keyboardListBoxes.Add(hidden.Keyboard.DeviceID, listBox1);
|
|
|
|
|
|
2007-09-21 21:30:18 +00:00
|
|
|
|
// Add available mice to the mouse input logger.
|
2007-09-26 11:47:30 +00:00
|
|
|
|
ChooseMouse.Items.Add(String.Format("Mouse {0} ({1})", 0, hidden.Mouse.Description));
|
|
|
|
|
hidden.Mouse.ButtonDown += LogMouseButtonDown;
|
|
|
|
|
hidden.Mouse.ButtonUp += LogMouseButtonUp;
|
2007-09-21 21:30:18 +00:00
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
hidden.Keyboard.KeyDown += LogKeyDown;
|
|
|
|
|
hidden.Keyboard.KeyUp += LogKeyUp;
|
|
|
|
|
|
|
|
|
|
//Application.Idle += new EventHandler(UpdateDevices);
|
|
|
|
|
hidden.UpdateFrame += hidden_UpdateFrame;
|
2007-09-22 13:13:17 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
void hidden_UpdateFrame(object sender, UpdateFrameEventArgs e)
|
2007-09-22 13:13:17 +00:00
|
|
|
|
{
|
2007-09-26 11:47:30 +00:00
|
|
|
|
//hidden.Poll();
|
2007-09-22 14:59:33 +00:00
|
|
|
|
|
2007-09-22 13:13:17 +00:00
|
|
|
|
// Update mouse coordinates.
|
2007-09-26 11:47:30 +00:00
|
|
|
|
MouseXText.Text = hidden.Mouse.X.ToString();
|
|
|
|
|
MouseYText.Text = hidden.Mouse.Y.ToString();
|
|
|
|
|
MouseDXText.Text = hidden.Mouse.XDelta.ToString();
|
|
|
|
|
MouseDYText.Text = hidden.Mouse.YDelta.ToString();
|
|
|
|
|
MouseWheelText.Text = hidden.Mouse.Wheel.ToString();
|
2007-09-22 13:13:17 +00:00
|
|
|
|
//MouseWheelDelta.Text = driver.Mouse[ChooseMouse.SelectedIndex].WheelDelta.ToString();
|
2007-09-21 20:45:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
void LogMouseButtonDown(MouseDevice sender, MouseButton button)
|
2007-09-21 21:30:18 +00:00
|
|
|
|
{
|
2007-09-22 14:59:33 +00:00
|
|
|
|
//Trace.WriteLine(String.Format("Mouse button down: {0} on device: {1}", button, sender.DeviceID));
|
2007-09-26 11:47:30 +00:00
|
|
|
|
if (sender.DeviceID == hidden.Mouse.DeviceID)
|
2007-09-22 13:13:17 +00:00
|
|
|
|
MouseButtons.Items.Add(button);
|
2007-09-21 21:30:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
void LogMouseButtonUp(MouseDevice sender, MouseButton button)
|
2007-09-21 21:30:18 +00:00
|
|
|
|
{
|
2007-09-22 14:59:33 +00:00
|
|
|
|
//Trace.WriteLine(String.Format("Mouse button up: {0} on device: {1}", button, sender.DeviceID));
|
2007-09-26 11:47:30 +00:00
|
|
|
|
if (sender.DeviceID == hidden.Mouse.DeviceID)
|
2007-09-22 13:13:17 +00:00
|
|
|
|
MouseButtons.Items.Remove(button);
|
2007-09-21 21:30:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
void LogKeyDown(KeyboardDevice sender, Key key)
|
2007-09-21 20:45:47 +00:00
|
|
|
|
{
|
2007-09-26 11:47:30 +00:00
|
|
|
|
Trace.WriteLine(String.Format("Key down: {0} on device: {1}", key, (sender as KeyboardDevice).DeviceID));
|
|
|
|
|
keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Add(key);
|
2007-09-21 20:45:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
void LogKeyUp(KeyboardDevice sender, Key key)
|
2007-09-21 20:45:47 +00:00
|
|
|
|
{
|
2007-09-26 11:47:30 +00:00
|
|
|
|
Trace.WriteLine(String.Format("Key up: {0} on device: {1}", key, (sender as KeyboardDevice).DeviceID));
|
|
|
|
|
keyboardListBoxes[(sender as KeyboardDevice).DeviceID].Items.Remove(key);
|
2007-09-21 20:45:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IExample Members
|
|
|
|
|
|
|
|
|
|
public void Launch()
|
|
|
|
|
{
|
|
|
|
|
// Empty
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-20 10:54:40 +00:00
|
|
|
|
public static readonly int order = 2;
|
|
|
|
|
|
2007-09-21 20:45:47 +00:00
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
}
|