No reaction to key presses etc

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
sandyw
Posts: 4
Joined: Fri Oct 12, 2007 1:48 am
Location: Wick, Scotland

No reaction to key presses etc

Post by sandyw »

Hello,

Can anybody help me with this.
I'm writing a program in c# 2005 and cannot get the code to see any keypresses from the SpaceNavigator. I know the code is connecting to the device as it reads in the correct device type and displays it, but it isn't seeing any key presses etc.

Heres the code;

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


namespace OE14_502_GUI
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}

void keyboard_KeyDown(int keyCode)
{
keystate.Text = keyCode.ToString();
}


private TDxInput.Device device;
private TDxInput.Sensor sensor;
private TDxInput.Keyboard keyboard;

private void btController_Click(object sender, EventArgs e)
{
try
{
if (btController.Text == "Connect 3D Controller")
{
device = new TDxInput.Device();
sensor = new TDxInput.Sensor();
keyboard = new TDxInput.Keyboard();

keyboard.KeyDown += new TDxInput._IKeyboardEvents_KeyDownEventHandler(keyboard_KeyDown);
//sensor.SensorInput += new TDxInput._ISensorEvents_SensorInputEventHandler(sensor_SensorInput);

device.Connect();

switch (device.Type)
{
case 0: MessageBox.Show("Unknown Controller Type connected", "OE14_502 GUI");
break;
case 4: MessageBox.Show("SpaceExplorer Controller Type connected", "OE14_502 GUI");
break;
case 6: MessageBox.Show("SpaceNavigator Controller Type connected", "OE14_502 GUI");
break;
case 25: MessageBox.Show("SpaceTraveller Controller Type connected", "OE14_502 GUI");
break;
case 29: MessageBox.Show("SpacePilot Controller Type connected", "OE14_502 GUI");
break;

default:
break;
}

btController.Text = "Disconnect 3D Controller";
}
}
catch (Exception ex)
{

}
}

private void frmMain_Load(object sender, EventArgs e)
{


}

private void frmMain_FormClosing(object sender, f :?: ormClosingEventArgs e)
{
device.Disconnect();
}
}
}

Any comments on why its not working and any tips on improving it?

thanks for any help

Sandyw :?:
sandyw
ngomes
Moderator
Moderator
Posts: 3344
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

Hi sandyw,

You're creating disjoint instances of the Device, Sensor and Keyboard objects. You should only create a "Device" and retrieve the references to the other objects from it.

We have a C# sample on the SDK page. There are also C# examples on this Forum (refer to this post).
Nuno Gomes
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

Also make sure the configuration file your application is using hasn't mapped the buttons to some internal driver functions. Go into the 3DxWare GUI and map the buttons to "Button 1" and "Button 2".
sandyw
Posts: 4
Joined: Fri Oct 12, 2007 1:48 am
Location: Wick, Scotland

No reaction to key presses etc

Post by sandyw »

Hello jwick, gnomes

Problem Solved.

It's obvios when it's pointed out. More care next time I think :oops:

Thank you for your help.
Also thanks for the tip about the buttons.


sandyw :D
sandyw
Post Reply