Go to Post The numbers that I gave were purely theoretical and should not be considered realistic - Karibou [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 09-07-2013, 15:06
Hekaitomix Hekaitomix is offline
Registered User
no team
 
Join Date: Jul 2013
Location: italy
Posts: 5
Hekaitomix is an unknown quantity at this point
Reading one Joystick (PS1/PS2) using slimDX and C#

Hello everybody. I've a problem. I've connected to the computer a joystick (PS1) to an adapter called "Konig electronic" which is connected to the pc through a usb cable. I want to control it with a c# program. I've used slimDX dll but it doesn't work. When i use a PSX simulation software the joystick works, but when i try to control it with a c# code it doesn't work. please help me.

I want to get the pressed buttons, from PS1 joystick, and display it into label2.

PS: Sorry for my bad english but i'm italian!

My C# project is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SlimDX.DirectInput;

namespace JoyStick
{
public partial class Form1 : Form
{
List<DeviceInstance> directInputList = new List<DeviceInstance>();
DirectInput directInput = new DirectInput();
SlimDX.DirectInput.Joystick gamepad;
SlimDX.DirectInput.JoystickState state;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
directInputList.AddRange(directInput.GetDevices(De viceClass.GameController, DeviceEnumerationFlags.AttachedOnly));
gamepad = new SlimDX.DirectInput.Joystick(directInput, directInputList[0].InstanceGuid);
}

private void button1_Click(object sender, EventArgs e)
{

timer1.Start();
}

private void button2_Click(object sender, EventArgs e)
{
//gamepad.Unacquire();
timer1.Stop();
}

private void timer1_Tick(object sender, EventArgs e)
{
if (gamepad.Acquire().IsFailure)
return;


if (gamepad.Poll().IsFailure)
return;


if (SlimDX.Result.Last.IsFailure)
return;

state = gamepad.GetCurrentState();

bool[] buttons = state.GetButtons();

for (int i = 0; i < buttons.Length; i++)
if (buttons[i])
label2.Text = i.ToString();

lbl_np.Text = Convert.ToString(buttons.Length);

gamepad.Unacquire();
}


}
}

Last edited by Hekaitomix : 09-07-2013 at 15:09.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi