Soyez le premier à donner votre avis sur cette source.
Snippet vu 14 360 fois - Téléchargée 19 fois
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Microsoft.DirectX; using Microsoft.DirectX.DirectInput; namespace test_manette { public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.IContainer components; private System.Windows.Forms.TextBox lbjoy; private System.Windows.Forms.Timer timer1; private Hashtable joy; public Form1() { InitializeComponent(); Device joystick=null; joy = new Hashtable(); int i=0; foreach( DeviceInstance di in Manager.GetDevices( DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)) { joy.Add(i,new Device(di.InstanceGuid)); i++; } if(joy.Count == 0) { MessageBox.Show("pas de manettes"); throw new Exception(); } //entre la variation des axes. for(i = 0; i<joy.Count;i++) { joystick = (Device)joy[i]; foreach(DeviceObjectInstance doi in joystick.Objects) { if((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0) { joystick.Properties.SetRange( ParameterHow.ById, doi.ObjectId, new InputRange(-5000,5000)); } } //met l'axe des manettes en mode absolue. joystick.Properties.AxisModeAbsolute = true; //change le niveau de cooperation. joystick.SetCooperativeLevel( this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background); //active le devices pour la capture. joystick.Acquire(); } } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.lbjoy = new System.Windows.Forms.TextBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // // lbjoy // this.lbjoy.Location = new System.Drawing.Point(0, 48); this.lbjoy.Multiline = true; this.lbjoy.Name = "lbjoy"; this.lbjoy.Size = new System.Drawing.Size(344, 112); this.lbjoy.TabIndex = 0; this.lbjoy.Text = "textBox1"; // // timer1 // this.timer1.Enabled = true; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(344, 310); this.Controls.Add(this.lbjoy); this.Name = "Form1"; this.Text = "Manette"; this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void timer1_Tick(object sender, System.EventArgs e) { Device joystick=null; string info=""; for(int y = 0; y<joy.Count;y++) { joystick = (Device)joy[y]; info += "Joystick["+y.ToString()+"]: "; //recupere le state du joystick. JoystickState state = joystick.CurrentJoystickState; //Capture les Positions. info += "X:" + state.X + " "; info += "Y:" + state.Y + " "; info += "Z:" + state.Z + " "; //Capture les boutons. byte[] buttons = state.GetButtons(); for(int i = 0; i < buttons.Length; i++) { if(buttons[i] != 0) { info += "Button:" + i + " "; } } info +="\r\n"; } lbjoy.Text = info; } } }
23 mars 2014 à 10:49
21 févr. 2014 à 23:11
est-ce que vous savez comment faire ça sous unity3d?
merci d'avance.
22 avril 2011 à 14:46
Si qq'un a une piste, je suis preneur.
21 août 2008 à 15:02
7 avril 2008 à 12:58
J'ai vu l'utilisation des boutons/joysticks, mais qu'en est-il de l'utilisation des retour de force ? J'ai déja tenté de les utiliser mais le code plantait littérallement :-(.
Bref, si tu peux l'ajouter, if possible, sinon tant pis ;-).
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.