I need to get the Data´s (X&Y values) of two different Mouses connected to one device.
I hope to get the Data via RawInputSharp (https://jstookey.com/arcade/rawmouse/) but the RawMouseDemo version in this Package is not working correctly. I get 3 different types of error codes:
and sometimes the Code runs perfectly.
I actually only need a variable in which the values are constantly written to process this further more.
I´m new to C# and do not fully understand the RawInputSharp library. Could someone please help me? Thanks.
Code used to get the errors:
public RawMouseDemo()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
//create and init
_rmInput = new RawMouseInput();
_rmInput.RegisterForWM_INPUT(this.Handle);
UpdateControls();
}
protected const int WM_INPUT = 0x00FF;
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case WM_INPUT:
//read in new mouse values.
_rmInput.UpdateRawMouse(m.LParam);
UpdateControls();
break;
}
base.WndProc(ref m);
}
protected void UpdateControls() {
if(_rmInput.Mice.Count > 0) {
RawMouse mouse1 = (RawMouse)_rmInput.Mice[0];
_mouse1X.Text = mouse1.X.ToString();
_mouse1Y.Text = mouse1.Y.ToString();
_mouse1Z.Text = mouse1.Z.ToString();
_mouse1Button1.Checked = mouse1.Buttons[0];
_mouse1Button2.Checked = mouse1.Buttons[1];
if(mouse1.Buttons.Length < 3) {
_mouse1Button3.Enabled = false;
_mouse1Z.Enabled = false;
} else {
_mouse1Button3.Checked = mouse1.Buttons[2];
}
} else {
_mouse1X.Enabled = false;
_mouse1Y.Enabled = false;
_mouse1Z.Enabled = false;
_mouse1Button1.Enabled = false;
_mouse1Button2.Enabled = false;
_mouse1Button3.Enabled = false;
}
if(_rmInput.Mice.Count > 1) {
RawMouse mouse2 = (RawMouse)_rmInput.Mice[1];
_mouse2X.Text = mouse2.X.ToString();
_mouse2Y.Text = mouse2.Y.ToString();
_mouse2Z.Text = mouse2.Z.ToString();
_mouse2Button1.Checked = mouse2.Buttons[0];
_mouse2Button2.Checked = mouse2.Buttons[1];
if(mouse2.Buttons.Length < 3) {
_mouse2Button3.Enabled = false;
_mouse2Z.Enabled = false;
} else {
_mouse2Button3.Checked = mouse2.Buttons[2];
}
} else {
_mouse2X.Enabled = false;
_mouse2Y.Enabled = false;
_mouse2Z.Enabled = false;
_mouse2Button1.Enabled = false;
_mouse2Button2.Enabled = false;
_mouse2Button3.Enabled = false;
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this._mouse1X = new System.Windows.Forms.TextBox();
this._mouse1Y = new System.Windows.Forms.TextBox();
this._mouse1Z = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this._mouse2Z = new System.Windows.Forms.TextBox();
this._mouse2Y = new System.Windows.Forms.TextBox();
this._mouse2X = new System.Windows.Forms.TextBox();
this._mouse1Button1 = new System.Windows.Forms.CheckBox();
this._mouse1Button2 = new System.Windows.Forms.CheckBox();
this._mouse1Button3 = new System.Windows.Forms.CheckBox();
this._mouse2Button3 = new System.Windows.Forms.CheckBox();
this._mouse2Button2 = new System.Windows.Forms.CheckBox();
this._mouse2Button1 = new System.Windows.Forms.CheckBox();
this.label7 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// _mouse1X
//
this._mouse1X.Location = new System.Drawing.Point(128, 16);
this._mouse1X.Name = "_mouse1X";
this._mouse1X.TabIndex = 0;
this._mouse1X.Text = "";
//
// _mouse1Y
//
this._mouse1Y.Location = new System.Drawing.Point(128, 40);
this._mouse1Y.Name = "_mouse1Y";
this._mouse1Y.TabIndex = 1;
this._mouse1Y.Text = "";
//
// _mouse1Z
//
this._mouse1Z.Location = new System.Drawing.Point(128, 64);
this._mouse1Z.Name = "_mouse1Z";
this._mouse1Z.TabIndex = 2;
this._mouse1Z.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.TabIndex = 10;
this.label1.Text = "Mouse 1 X";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 40);
this.label2.Name = "label2";
this.label2.TabIndex = 11;
this.label2.Text = "Mouse 1 Y";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 64);
this.label3.Name = "label3";
this.label3.TabIndex = 12;
this.label3.Text = "Mouse 1 Z";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 144);
this.label4.Name = "label4";
this.label4.TabIndex = 18;
this.label4.Text = "Mouse 2 Z";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 120);
this.label5.Name = "label5";
this.label5.TabIndex = 17;
this.label5.Text = "Mouse 2 Y";
//
// label6
//
this.label6.Location = new System.Drawing.Point(16, 96);
this.label6.Name = "label6";
this.label6.TabIndex = 16;
this.label6.Text = "Mouse 2 X";
//
// _mouse2Z
//
this._mouse2Z.Location = new System.Drawing.Point(128, 144);
this._mouse2Z.Name = "_mouse2Z";
this._mouse2Z.TabIndex = 15;
this._mouse2Z.Text = "";
//
// _mouse2Y
//
this._mouse2Y.Location = new System.Drawing.Point(128, 120);
this._mouse2Y.Name = "_mouse2Y";
this._mouse2Y.TabIndex = 14;
this._mouse2Y.Text = "";
//
// _mouse2X
//
this._mouse2X.Location = new System.Drawing.Point(128, 96);
this._mouse2X.Name = "_mouse2X";
this._mouse2X.TabIndex = 13;
this._mouse2X.Text = "";
//
// _mouse1Button1
//
this._mouse1Button1.Location = new System.Drawing.Point(248, 16);
this._mouse1Button1.Name = "_mouse1Button1";
this._mouse1Button1.Size = new System.Drawing.Size(72, 24);
this._mouse1Button1.TabIndex = 19;
this._mouse1Button1.Text = "Button 1";
//
// _mouse1Button2
//
this._mouse1Button2.Location = new System.Drawing.Point(248, 40);
this._mouse1Button2.Name = "_mouse1Button2";
this._mouse1Button2.Size = new System.Drawing.Size(72, 24);
this._mouse1Button2.TabIndex = 20;
this._mouse1Button2.Text = "Button 2";
//
// _mouse1Button3
//
this._mouse1Button3.Location = new System.Drawing.Point(248, 64);
this._mouse1Button3.Name = "_mouse1Button3";
this._mouse1Button3.Size = new System.Drawing.Size(72, 24);
this._mouse1Button3.TabIndex = 21;
this._mouse1Button3.Text = "Button 3";
//
// _mouse2Button3
//
this._mouse2Button3.Location = new System.Drawing.Point(248, 144);
this._mouse2Button3.Name = "_mouse2Button3";
this._mouse2Button3.Size = new System.Drawing.Size(72, 24);
this._mouse2Button3.TabIndex = 24;
this._mouse2Button3.Text = "Button 3";
//
// _mouse2Button2
//
this._mouse2Button2.Location = new System.Drawing.Point(248, 120);
this._mouse2Button2.Name = "_mouse2Button2";
this._mouse2Button2.Size = new System.Drawing.Size(72, 24);
this._mouse2Button2.TabIndex = 23;
this._mouse2Button2.Text = "Button 2";
//
// _mouse2Button1
//
this._mouse2Button1.Location = new System.Drawing.Point(248, 96);
this._mouse2Button1.Name = "_mouse2Button1";
this._mouse2Button1.Size = new System.Drawing.Size(72, 24);
this._mouse2Button1.TabIndex = 22;
this._mouse2Button1.Text = "Button 1";
//
// label7
//
this.label7.Location = new System.Drawing.Point(328, 8);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(64, 16);
this.label7.TabIndex = 25;
this.label7.Text = "Click Area:";
//
// RawMouseDemo
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(520, 182);
this.Controls.Add(this.label7);
this.Controls.Add(this._mouse2Button3);
this.Controls.Add(this._mouse2Button2);
this.Controls.Add(this._mouse2Button1);
this.Controls.Add(this._mouse1Button3);
this.Controls.Add(this._mouse1Button2);
this.Controls.Add(this._mouse1Button1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this._mouse2Z);
this.Controls.Add(this._mouse2Y);
this.Controls.Add(this._mouse2X);
this.Controls.Add(this._mouse1Z);
this.Controls.Add(this._mouse1Y);
this.Controls.Add(this._mouse1X);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "RawMouseDemo";
this.Text = "RawMouseDemo";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new RawMouseDemo());
}
}
}
User contributions licensed under CC BY-SA 3.0