Hey. I know you guys are working on a user's manual but I've got to ask this question to help me with my development with my current project.

What data type do you use to identify what keyboard button, mouse button, or joystick button was pressed?

I saw in Axis.Identifier there is a method called getName() and that returns a String.

I am guessing that all keyboard, mouse, and joystick buttons inheret from this class. So would I be safe to use Strings for holding keyboard/mouse/joystick buttons to determine what action needs to associate with these buttons or can I get that information another way, such as the use of ints?

Also, what is the performance differnce from making a buch of string comparisons as apposed to integer comparisions?

So say when 'a' is pressed on the keyboard you want an action to be performed.

How do u check that 'a' was pressed?

In other libraries such as JavaJoystick, you get a unique ID for each button. I would just make an integer comparision to see if key 'a' (which has a unique number) is equal to the number that the button returned.

Can u do that in JInput? Jeff: you stated that you check the refernce of the Axis object. Well, how do u know that the object in which you are checking the refernce from points to the button 'a'?

Some sourcecode from our game which will be use JInput. We use this class for general checking of Axis instances against a specific value. We call this the extend value. not pressed value because some axis can have two such values (eg. gamepad).

Such an AxisInput is created like this: new AxisInput(xAxis, -1).This delivers true on isTriggered() whenever one presses to the left on my gamepad.

The hard thing is how do I find my xAxis object? The code above is somewhat silly because it is hardcoded to my gamepad only. I see no problems when I the user has to interact and press something and the game simply polls every available axis object to find out which one has been used.Now imagine I want to save the input configuration to disk and use it when the app is restarted.

AH this is a real issue. Somethign I've doena bit of digging on but am stalled ebcause of other thinsg right now.

Initially it was thought that there shoulf be standard Axis names.

On windows the name of the 'a' button is "A".

Unfrotunately this doesnt work right yet on mac which returns the truely helpful "buttonXXX" or something approaching that.

We're still tryign tod ecide the rigth way to handle that.I lean towards converting the names to standard in the plug-in myself but we're trying to get a sensible answer otu of Apple as to what the "right" way is on their platform even in native code to recognize this.

Got a question about Java and game programming? Just new to the Java Game Development Community? Try my FAQ. Its likely you'll learn something!

Hi One way of doing this is to get the button names using some kind of configurator dialog, 'Please press the button you wish to use for 'forwards' (We recomend the 'A' key)', or something like that, it's not ideal, but it should get you going till we figure something better out in the plugins layer.

Isn't this an even more scary issues since drivers on Windows seems to be able to be able to define their own button names (at least thats the way it appeared when I tried this stuff out).

So, although you could map some commonly expected keys to some standardised values in the plugin, you'd still have random names for the buttons on a controller..

Unless of course thats fine, expected keys can be mapped using some HardwareToJava(int Code) mapping function on the plugin and anything else just returns unknown, leaving the developer to deal with it as Endolf suggests above.

So the way JavaJoystick handles naming is that it detects the joystick buttons and assings them an id. The actual name isn't important.

Then you can check if button 1 is held down via a mask.

For instance say you have detected a Joystick j

you call a method

1

intcurButtonsPressed = j.getButtons();

curButtonsPressed is a button mask. To find out if say BUTTON6 was pressed do this:

1 2 3

if(j.Button6 & curButtonsPressed) > 0){//button 6 was pressed}

I really like this because its very straight forward and easy to use.I still have no idea how you detect when specific buttons are being pressed in jinput.

Maybe you guys should look at JavaJoystick. I know they don't have all the featurs you have like forcefeed back and it only works for windows and linux, but I was able to use their stuff without much trouble at all.

Axis name - is what you display to the user (it may be translated to a users locale), but the Axis 'Identifier' name is a constant for known axis types (e.g. uppercase letter for most keyboard keys, some definition to come for gamepad buttons, etc.)

We need a standard convention for naming Identifiers for the case of gamepad buttons and sticks, where there could be two sticks (left and right) or a single stick. E.g. do we call it 'left stick' if there is only one? How do we code a game that wants a stick control if that could be named 'left stick' or 'stick 1' or whatever..

This needs a little design time... so that the code that the game programmers are writing is as straight-forward as possible.

Even if we need a bunch of helper methods to go with JInput for things like 'get directional controllers', 'get default directional controller', maybe a prefs system for things like 'default fire/attack button, 'default jump button', 'default use/action button' (similar for 'select' button, 'start' button, etc...)

Hi Did you ever wonder why most games default to the first two axis and first 4+ buttons on the first controller it finds. It's because they can be called anything they like (on windows, not under linux, dunno about mac). It really is up to the driver writers and there is nothing we can do about that one. Helper methods could be done, and i've been pondering a 'detect which axis has just been moved and in what direction' and 'which button has just been pressed' helper for game configs, the defaults just have to be 'get the first 4 buttons from a game controller' or 'get the first 3 axis from a game controller' (you can get the controller type, and this should be set). Of course this goes a little pear shapped under linux, when the axis names aren't applied right in the kernel, for example, my analog 3 axis 4 button gameport style joystick has listed a Z axis instead of a throttle, nowt can be done about it in jinput as it's a kernel level problem (don't have any other gameports to try any other joysticks). I think for my own purposes I'll be using the device name, and then just Axis 1, Axis 2, button 1, button 2 naming, overiding what jinput thinks as it's just too much out of our hands.

Hi Thanks, as root, can you do a chmod o+rw /dev/input/* and try again?, also, you don't have the event system in your kernel (option CONFIG_INPUT_EVDEV in the .config file for your kernel)or from the kernel config tool

Device Drivers -> Input device support -> Event interface

if it's a module then you need to load it, i've built it in on my test machine, but have tried it as a module before.

Hi To send messages to the devices (like for force feedback and some of the other diagnositics/setup information) it needs to be writeable (else you can't write the message ). I think that some devices could be opened read only, queried, and then work out if I need write access, but for now it (and when I was developing it) having write access as well didn't seem like an issue. I did want to print an error message when it failed to open a devices, so that it was obvious where the error was, but some distributions include a whole list of device files regardless of wether they exist or not, jinput will try and open them, so you would always get error messages there that it couldn't open the device, I might put this back in though.

This all looks logical until "type.equals(Controller.Type.UNKNOWN))". The problem is that under Linux no device identifies itself as a gamepad or stick with the corresponding Controller.Type instance. If I leave the last check out the gamepad is not found in Linux (but this works in Windows ).

Another bad thing: In another thread I have shown you that my PC speaker is now a Controller as well and is now recognized by this method. Very bad because I wanted a pad or joystick-like device

This is the first thing I want to see corrected.

2)Regarding the primary problem of this thread (identify used Axis at runtime, save something into a config file, find the Axis which was described in the config file) I would propose generating something like a unique identifier. This identifier should include device name and manufacturer.In Linux I think it would be a good idea to include the name of the device filename as well because this makes the identifier truly unique.

With that information it would be very easy what to save to a config file:

When the game is started and no controller is found with a corresponding identifier the game would know that it should be careful using another device because subcontroller and/or axis may not exist any more. Auto sensing them again would solve that easily.

Other platforms should be able to follow that to: In Windows you can use DirectInput's device type and the order in which DInput gives you the device.

Hi I know it's been a while since you posted this, but I am working on it. Currently I have some sigsegv's under linux, which I think is due to my logitec keyboard which has two sub controllers, one for the main qwerty bit, and one for the mouse wheel, the volume controls etc etc, hopefully I can get this resolved soon and get back to you.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org