Sign in to follow this  
leandra

DirectInput Managed C# mouse wheel

Recommended Posts

I have a mouse with mouse wheel and when I print to screen my mousestate.Z position is always 0 , how can my mouse device know if I have a mouse wheel???? this is the code mouse = new Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse); mouse.SetCooperativeLevel(Hwnd, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive); mouse.Properties.AxisModeAbsolute = true; mouse.Acquire(); MouseState state = mouse.CurrentMouseState; info += "X:" + state.X + " "; info += "Y:" + state.Y + " "; info += "Z:" + state.Z + " ";

Share this post


Link to post
Share on other sites
the mouse wheel doesnt have a position - it only has a change in position.
set the axis mode to relative and try :)


EDIT:
Hmm. I should check my code before answering in future. You're right GroZZleR (below), it does have absolute coordinates - thats what i check myself :p

[Edited by - Wyzfen on June 23, 2005 7:30:24 AM]

Share this post


Link to post
Share on other sites
The mouse wheel absolutely has absolute coordinates. (heh)

Where are you calling your mouse.GetCurrentState code from? Is it in a loop? The mouse wheel position always starts off at 0 when you acquire the device, so you need to loop and update to get accurate information.

I just finished writing my DirectInput test code myself, you're more than welcome to check it out:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using DirectInput = Microsoft.DirectX.DirectInput;

namespace DirectInputCrap
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox uiMouse;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <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.uiMouse = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// uiMouse
//
this.uiMouse.Location = new System.Drawing.Point(6, 5);
this.uiMouse.Multiline = true;
this.uiMouse.Name = "uiMouse";
this.uiMouse.ReadOnly = true;
this.uiMouse.Size = new System.Drawing.Size(280, 256);
this.uiMouse.TabIndex = 0;
this.uiMouse.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.uiMouse);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using(Form1 app = new Form1())
{
app.Show();

DirectInput.Device mouse = null;

try
{
mouse = new DirectInput.Device(DirectInput.SystemGuid.Mouse);
mouse.SetCooperativeLevel(app, DirectInput.CooperativeLevelFlags.Background | DirectInput.CooperativeLevelFlags.NonExclusive);
mouse.Properties.AxisModeAbsolute = true;
mouse.Acquire();
}
catch
{
MessageBox.Show("Unable to create / acquire mouse");
app.Close();
return;
}

StringBuilder mouseInfo = new StringBuilder();

while(app.Created)
{
DirectInput.MouseState state = mouse.CurrentMouseState;

mouseInfo.Remove(0, mouseInfo.Length);
mouseInfo.Append(String.Format("{0},{1} x {2}", state.X, state.Y, state.Z));
app.uiMouse.Text = mouseInfo.ToString();

Application.DoEvents();
}
}
}
}
}



It's a little messy.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this