Is this possible right now?

Hi guys,

since i’ve never touched jinput yet and am not so aware about its developpement stage, i’m wondering about few things, and if they’re doable right now.

A. Keyboard

Is it possible to get a sort of “isKeyPressed(int keyCode)” information directly?
(I mean a direct access of course, not a layer which sets a true/false flag on key events.)

B. Mouse

Is it possible to “block” the cursor completely? or into a given area?
Is it possible to get the dx/dy directly? (i mean, to get it even when the cursor is out of the window or even if the cursor doesn’t move at all, when it’s blocked or against the border)

If you could give me some sample code, it would even be more appreciated. Well, it’s really needed since i’ve no clue on how it works at all. :stuck_out_tongue:

cheers

check out the jinputtester app, which is posted athttp://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jinput;action=display;num=1064360336

it has source code included.

soon as the mouse bug with directx is sorted out, all of those things will be possible, except mouse blocking (i think)

if you’re doing a full-screen app and want to use jinput for mouse input you will have to draw the cursor and track its position yourself, which leaves the blocking up to you. as for windowed apps im not sure, but just yet, i dont think there’s a way to lock the mouse so the OS doesnt let you click outside of the window.

AWT lets you get the exact location of the pointer, but leaves problems for eg. FPS games, but for an RTS or mouse based games, if you’re already using AWT, it may be more predictable for your users. (mouse will move at same speed in game as it does in OS for instance)

(1) Yes. It is a polled input library that supprots keyboard. Hviong said that, the Win32 plug-in currently queues key-strokes but we’ve had an action item to fix that for awhile now.

(2) JInput has nothing to do with cursors. It is purely a low level inpout device API. A cursor is an output device.

(3) A mouse is a relative input device, so yes, it returns dx/dy. It has no idea of “cursor psoition”, thats a highelr level construct that the OS typically layers ontop.

Again, the one caveat is that the mouse code in the WIn32 plug-in is currently returning “normalized” data which needs to be changed.

ah, cool! thanks for the infos. :slight_smile:

btw, could you also give me the few lines needed? it would really save me a lot of time! :stuck_out_tongue:

The general idea is the following:

setup controller environment:
Controller[] controllers = ControllerEnvironment.getDefaultControllerEnvironment().getControllers();

Now you have to find the controller you want: You can do this by checking Controller.getType():

myController = retrieveMyController(controllers);

Each controller contains an array of axes (may be empty!) and/or subcontrollers (may be empty as well!).

Typically a gamepad with 4 buttons contains 6 axes:

  • 2 for the directions
  • 4 for the buttons

Access to all axes is made through Controller.getAxes(). You can determine the type of an axis with Axis.getType().

To read current data from the controller you have to poll it with: Controller.poll()
After that you can retrieve the value of each axis using Axis.getPollData()

When the axis is normalized (keyboard, buttons, etc) you get values in the range [-1,1]. Negative values only make sense for directions on a gamepad/joystick. 0.0 generally means unpressed and 1.0 pressed. Values in between can be generated form analog devices (e.g: joystick).

Analog devices usually never have a relased/unpressed state in which they report 0.0. They differ from that in positive AND negative direction by an amount that can be retrieved with Axes.getDeadZone().

Note: Currently the mouse device is implemented differently on the major plattforms Lin/Mac and Win. On Windows the mouse generates normalized delta values when the Linux/MacOS X version is not nomalized.