Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  The data type used for identifying key/butt press  (Read 7300 times)
0 Members and 1 Guest are viewing this topic.
Offline Conzar

Junior Member




There is nothing common about common sense


« Posted 2004-03-19 17:58:59 »

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?

Thanks


Ubuntu
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2004-03-20 02:12:02 »

String comaprison is a lot more CPU. Whether it makes a difference in your app is a toss up really as you are talking "not much" comapred to "almost none."

Still I'd avoid it in general.

An Axis object represents one value be it a button, one axis of a stick, or what have you.  I'd base the mapping on Axis object to what it controls, myself.

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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #2 - Posted 2004-03-20 11:39:15 »

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'?

Thanks

Ubuntu
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #3 - Posted 2004-03-22 08:11:33 »

Hi
 Does this mean your keyboard test program works now?, just checking, because if it does, then I'll look at something else tonight.

Cheers

Endolf

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #4 - Posted 2004-03-22 15:39:22 »

nah, the keyboard test doesn't work.  I'm trying to code up my application so that when jinput does work for me, I will be able to plugin jinput stuff.

Ubuntu
Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #5 - Posted 2004-03-24 11:47:43 »

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).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
private class AxisInput implements PollingInput {
        private Axis axis;
        private boolean isTriggered;
        private float extendValue;
        private boolean override;
        private float deadZone;
       
        AxisInput(Axis newAxis, float newExtendValue) {
            axis = newAxis;
            deadZone = axis.getDeadZone() + 0.1f;
           
            extendValue = newExtendValue;
           
            // this adds this Input object to a List<PollingInput> were
          // it is polled at certain times
           pollingInputs.add(this);
        }
       
        public boolean isTriggered() {
            return isTriggered;
        }
       
        public void reset() {
            // this is a feature of our Input objects: you can reset them
           // to force the user to press the again to get it recognized
           override = true;
           
            isTriggered = false;
        }
       
        public void poll() {
            // this updates the triggered state
           boolean newTriggered = Math.abs(axis.getPollData()-extendValue) <= deadZone;
           
            // handles proper resetting
           if(override) {
                if(!newTriggered) {
                    override = false;
                }
            } else {
                isTriggered = newTriggered;
            }
        }
    }


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.

What information should I write into a file?

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #6 - Posted 2004-03-25 15:52:40 »

Thats exactly what I was trying to get at.

Like how do u know 'a' was pressed or game controller button1 was pressed.

Ubuntu
Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2004-04-01 22:00:40 »

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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #8 - Posted 2004-04-02 07:06:53 »

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.

Cheers

Endolf

Online kevglass

JGO Kernel


Medals: 171
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #9 - Posted 2004-04-02 07:20:57 »

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.

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #10 - Posted 2004-04-02 11:13:18 »

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  
int curButtonsPressed = 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.


http://sourceforge.net/projects/javajoystick/

Ubuntu
Offline Jeff

JGO Coder




Got any cats?


« Reply #11 - Posted 2004-04-04 21:25:36 »

The problem is that just means that the mappings have been hardcoded in the LWJGL joystick code.

As mentioned before we could do that with the names in our plug-ins but if the underlying system driver decided to do somethign different it would fail invisibly Sad

We are tryign to fidn otu what the "right way' is from the gusy who make the OS in the cas eof OSX and i wouldn't want to hack sucha  hardcoded solution untilw e have an answer.

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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #12 - Posted 2004-04-04 23:56:18 »

So basically, u are saying not to use JINPUT until u guys get this figured out?

Ubuntu
Offline Jeff

JGO Coder




Got any cats?


« Reply #13 - Posted 2004-04-05 01:51:07 »

Quote
So basically, u are saying not to use JINPUT until u guys get this figured out?


Nope.

I am saying either build the translation table yourself or let your user do it through key assignment at start up.

OR if you vcan't wait fro someoen else to get to it, do the reasearch and propsoe a proper fix yourself.  Thats the great thing abotu open source. If you don't like the way it is, you can change it Smiley


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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #14 - Posted 2004-04-05 13:06:54 »

Roger that.
Maybe I'll write a class that handles this functionality that way it won't disturbe the core arch.

So I checked-out jinput and am unable to get any information back from my controllers, keyboards, and mice.

I ran readtest and only 1 window opened up.  Nothing was added to that window either (it was a blank JPanel (Frame or whatever)).

Here is the output from the command line

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
readtest:
     [java] Scanning jar: linux.jar
     [java] Examining file : META-INF/
     [java] Examining file : META-INF/MANIFEST.MF
     [java] Examining file : net/
     [java] Examining file : net/java/
     [java] Examining file : net/java/games/
     [java] Examining file : net/java/games/input/
     [java] Examining file : net/java/games/input/LinuxAxis.class
     [java] Examining file : net/java/games/input/LinuxDevice$LinuxHat.class
     [java] Examining file : net/java/games/input/LinuxDevice$ButtonID.class
     [java] Examining file : net/java/games/input/LinuxDevice$1.class
     [java] Examining file : net/java/games/input/LinuxDevice.class
     [java] Examining file : net/java/games/input/LinuxEnvironmentPlugin.class
     [java] Found candidate class: net/java/games/input/LinuxEnvironmentPlugin.class
     [java] Adding class to plugins:net.java.games.input.LinuxEnvironmentPlugin
     [java] Examining file : net/java/games/input/LinuxKeyboard$KeyID.class
     [java] Examining file : net/java/games/input/LinuxKeyboard.class
     [java] Examining file : net/java/games/input/LinuxMouse$LinuxMouseBall.class
     [java] Examining file : net/java/games/input/LinuxMouse$LinuxMouseButtons.class
     [java] Examining file : net/java/games/input/LinuxMouse$LinuxMouseButton.class
     [java] Examining file : net/java/games/input/LinuxMouse.class
     [java] Examining file : net/java/games/input/LinuxNativeTypesMap.class
     [java] Examining file : net/java/games/input/NativeDefinitions.class


thanks



Ubuntu
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #15 - Posted 2004-04-05 13:12:42 »

Hi
 That sounds (and looks) very much like it found the linux plugin, but no devices. Does non CVS code find everything OK?

Cheers

Endolf

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #16 - Posted 2004-04-05 14:16:41 »

So if I'm following this correctly...

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...)

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #17 - Posted 2004-04-05 14:33:01 »

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.

HTH

Endolf

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #18 - Posted 2004-04-06 12:09:22 »

Quote

That sounds (and looks) very much like it found the linux plugin, but no devices. Does non CVS code find everything OK?


Nope, it does the same thing.

Ubuntu
Offline Jeff

JGO Coder




Got any cats?


« Reply #19 - Posted 2004-04-06 19:55:27 »

This may have been asked already but what version of Linux are you using? JInput only supports fairly recent kernels.

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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #20 - Posted 2004-04-07 01:46:30 »

look at my signature.

But yea, I am using 2.6.3 kernel.  I have also had problems with the 2.6.1 kernel as well.

Ubuntu
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #21 - Posted 2004-04-07 12:25:18 »

Can you give me a list of what you have plugged in, and what interfaces they use (ps2/usb/gameport etc), and also the output of this
1  
whoami ; groups  ; ls -la /dev/input


Thanks

Endolf

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #22 - Posted 2004-04-07 16:06:42 »


Devices:
Mouse = Microsoft intelimouse - usb
Keyboard = PS2 (generic)
Joystick = Saitek X45 - usb

1  
2  
3  
4  
5  
6  
7  
8  
9  
mspeth@fmp mspeth $ whoami ; groups ; ls -la /dev/input
mspeth
users wheel audio games
total 0
drwxr-xr-x    1 root     root            0 Jan  1  1970 .
drwxr-xr-x    1 root     root            0 Jan  1  1970 ..
crw-r--r--    1 root     root      13,   0 Jan  1  1970 js0
crw-r--r--    1 root     root      13,  63 Jan  1  1970 mice
crw-r--r--    1 root     root      13,  32 Jan  1  1970 mouse0



BTW, I can use the X45 in other games like BF1942 (using wine).

Thanks

Ubuntu
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #23 - Posted 2004-04-08 10:38:54 »

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.

HTH

Jeremy

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #24 - Posted 2004-04-08 12:37:12 »

Hey.  Ok I recompiled the kernel with the event interface turned on.

Now the keyboard and mouse are getting read but the joystick is not I think (a window comes up for the joystick but nothing is in it).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
mspeth@fmp coreAPI $ whoami ; groups ; ls -la /dev/input
mspeth
users wheel audio games
total 0
drwxr-xr-x    1 root     root            0 Jan  1  1970 .
drwxr-xr-x    1 root     root            0 Jan  1  1970 ..
crw-r--rw-    1 root     root      13,  64 Jan  1  1970 event0
crw-r--rw-    1 root     root      13,  65 Jan  1  1970 event1
crw-r--r--    1 root     root      13,  66 Jan  1  1970 event2
crw-r--r--    1 root     root      13,   0 Jan  1  1970 js0
crw-r--rw-    1 root     root      13,  63 Jan  1  1970 mice
crw-r--rw-    1 root     root      13,  32 Jan  1  1970 mouse0


What do u guys think?

Ubuntu
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #25 - Posted 2004-04-08 13:50:25 »

Hi
 I think that js0 and event2 are the joystick, and they are both read only. Smiley

HTH

Endolf

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #26 - Posted 2004-04-08 13:58:44 »

Yep, thats it.  Why do u need write access on those devices?

Ubuntu
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #27 - Posted 2004-04-13 07:32:32 »

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 Smiley). 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.

Cheers

Endolf

Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #28 - Posted 2004-04-15 20:14:51 »

1)
@endolf: You asked my for some code regarding the topic of finding the right controller. Well lets have a look at this. It is currently used to find my gamepad.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
private Controller getStick(Controller[] controllers) {
        for(int i=0;i<controllers.length;i++) {
            Controller.Type type = controllers[i].getType();
            if(type.equals(Controller.Type.GAMEPAD) ||
            type.equals(Controller.Type.STICK) ||
            type.equals(Controller.Type.UNKNOWN)) {
                return controllers[i];
            }
        }
       
        return null;
    }


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 Sad ).

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 Cry

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:

- controller id
- [subcontroller index]
- axis index
- extend value
- game event

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.

So what do you think about that?

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #29 - Posted 2004-04-21 06:55:36 »

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.

Cheers

Endolf

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!