From 93fc9ce367e3f49dbbd508594dfb30c66921debd Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 21 Sep 2007 20:45:47 +0000 Subject: [PATCH] Added S04: Input Logger test. --- .../Tests/S04_Input_Logger.Designer.cs | 197 ++++++++++++++++++ Source/Examples/Tests/S04_Input_Logger.cs | 98 +++++++++ Source/Examples/Tests/S04_Input_Logger.resx | 120 +++++++++++ 3 files changed, 415 insertions(+) create mode 100644 Source/Examples/Tests/S04_Input_Logger.Designer.cs create mode 100644 Source/Examples/Tests/S04_Input_Logger.cs create mode 100644 Source/Examples/Tests/S04_Input_Logger.resx diff --git a/Source/Examples/Tests/S04_Input_Logger.Designer.cs b/Source/Examples/Tests/S04_Input_Logger.Designer.cs new file mode 100644 index 00000000..9f412ff1 --- /dev/null +++ b/Source/Examples/Tests/S04_Input_Logger.Designer.cs @@ -0,0 +1,197 @@ +namespace Examples.Tests +{ + partial class S04_Input_Logger + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tabControl = new System.Windows.Forms.TabControl(); + this.Keyboard = new System.Windows.Forms.TabPage(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.listBox4 = new System.Windows.Forms.ListBox(); + this.listBox3 = new System.Windows.Forms.ListBox(); + this.listBox2 = new System.Windows.Forms.ListBox(); + this.listBox1 = new System.Windows.Forms.ListBox(); + this.Mouse = new System.Windows.Forms.TabPage(); + this.HID = new System.Windows.Forms.TabPage(); + this.tabControl.SuspendLayout(); + this.Keyboard.SuspendLayout(); + this.SuspendLayout(); + // + // tabControl + // + this.tabControl.Controls.Add(this.Keyboard); + this.tabControl.Controls.Add(this.Mouse); + this.tabControl.Controls.Add(this.HID); + this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabControl.Location = new System.Drawing.Point(0, 0); + this.tabControl.Name = "tabControl"; + this.tabControl.SelectedIndex = 0; + this.tabControl.Size = new System.Drawing.Size(432, 378); + this.tabControl.TabIndex = 0; + // + // Keyboard + // + this.Keyboard.BackColor = System.Drawing.SystemColors.ControlLight; + this.Keyboard.Controls.Add(this.label4); + this.Keyboard.Controls.Add(this.label3); + this.Keyboard.Controls.Add(this.label2); + this.Keyboard.Controls.Add(this.label1); + this.Keyboard.Controls.Add(this.listBox4); + this.Keyboard.Controls.Add(this.listBox3); + this.Keyboard.Controls.Add(this.listBox2); + this.Keyboard.Controls.Add(this.listBox1); + this.Keyboard.Location = new System.Drawing.Point(4, 22); + this.Keyboard.Name = "Keyboard"; + this.Keyboard.Padding = new System.Windows.Forms.Padding(3); + this.Keyboard.Size = new System.Drawing.Size(424, 352); + this.Keyboard.TabIndex = 0; + this.Keyboard.Text = "Keyboard"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(207, 180); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(61, 13); + this.label4.TabIndex = 7; + this.label4.Text = "Keyboard 4"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 180); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(61, 13); + this.label3.TabIndex = 6; + this.label3.Text = "Keyboard 3"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(207, 3); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(61, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Keyboard 2"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(8, 3); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(61, 13); + this.label1.TabIndex = 4; + this.label1.Text = "Keyboard 1"; + // + // listBox4 + // + this.listBox4.FormattingEnabled = true; + this.listBox4.Location = new System.Drawing.Point(210, 197); + this.listBox4.Name = "listBox4"; + this.listBox4.Size = new System.Drawing.Size(206, 147); + this.listBox4.TabIndex = 3; + // + // listBox3 + // + this.listBox3.FormattingEnabled = true; + this.listBox3.Location = new System.Drawing.Point(9, 197); + this.listBox3.Name = "listBox3"; + this.listBox3.Size = new System.Drawing.Size(195, 147); + this.listBox3.TabIndex = 2; + // + // listBox2 + // + this.listBox2.FormattingEnabled = true; + this.listBox2.Location = new System.Drawing.Point(210, 20); + this.listBox2.Name = "listBox2"; + this.listBox2.Size = new System.Drawing.Size(206, 147); + this.listBox2.TabIndex = 1; + // + // listBox1 + // + this.listBox1.FormattingEnabled = true; + this.listBox1.Location = new System.Drawing.Point(9, 20); + this.listBox1.Name = "listBox1"; + this.listBox1.Size = new System.Drawing.Size(195, 147); + this.listBox1.TabIndex = 0; + // + // Mouse + // + this.Mouse.Location = new System.Drawing.Point(4, 22); + this.Mouse.Name = "Mouse"; + this.Mouse.Padding = new System.Windows.Forms.Padding(3); + this.Mouse.Size = new System.Drawing.Size(424, 339); + this.Mouse.TabIndex = 1; + this.Mouse.Text = "Mouse"; + this.Mouse.UseVisualStyleBackColor = true; + // + // HID + // + this.HID.Location = new System.Drawing.Point(4, 22); + this.HID.Name = "HID"; + this.HID.Padding = new System.Windows.Forms.Padding(3); + this.HID.Size = new System.Drawing.Size(424, 339); + this.HID.TabIndex = 2; + this.HID.Text = "HID"; + this.HID.UseVisualStyleBackColor = true; + // + // S04_Input_Logger + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(432, 378); + this.Controls.Add(this.tabControl); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "S04_Input_Logger"; + this.Text = "S04: Input Logger"; + this.tabControl.ResumeLayout(false); + this.Keyboard.ResumeLayout(false); + this.Keyboard.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TabControl tabControl; + private System.Windows.Forms.TabPage Keyboard; + private System.Windows.Forms.TabPage Mouse; + private System.Windows.Forms.TabPage HID; + private System.Windows.Forms.ListBox listBox4; + private System.Windows.Forms.ListBox listBox3; + private System.Windows.Forms.ListBox listBox2; + private System.Windows.Forms.ListBox listBox1; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + + } +} \ No newline at end of file diff --git a/Source/Examples/Tests/S04_Input_Logger.cs b/Source/Examples/Tests/S04_Input_Logger.cs new file mode 100644 index 00000000..616ca028 --- /dev/null +++ b/Source/Examples/Tests/S04_Input_Logger.cs @@ -0,0 +1,98 @@ +using System; +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 keyboardListBoxes = new Dictionary(4); + + public S04_Input_Logger() + { + InitializeComponent(); + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + WindowInfo info = new WindowInfo(this); + driver = new InputDriver(info); + Debug.Print("Keyboard count: {0}", driver.Keyboard.Count); + + 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; + } + + foreach (OpenTK.Input.Keyboard k in driver.Keyboard) + { + k.KeyDown += new KeyDownEvent(LogKeyDown); + k.KeyUp += new KeyUpEvent(LogKeyUp); + } + } + + void LogKeyDown(object sender, Key key) + { + Debug.Print("Key down: {0} on device: {1}", key, (sender as Keyboard).DeviceID); + keyboardListBoxes[(sender as Keyboard).DeviceID].Items.Add(key); + } + + void LogKeyUp(object sender, Key key) + { + keyboardListBoxes[(sender as Keyboard).DeviceID].Items.Remove(key); + } + + #region IExample Members + + public void Launch() + { + // Empty + } + + #endregion + } +} \ No newline at end of file diff --git a/Source/Examples/Tests/S04_Input_Logger.resx b/Source/Examples/Tests/S04_Input_Logger.resx new file mode 100644 index 00000000..ff31a6db --- /dev/null +++ b/Source/Examples/Tests/S04_Input_Logger.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file