Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Jinput how to identify buttons and sliders in event queue  (Read 1362 times)
0 Members and 1 Guest are viewing this topic.
Offline maxbit89

Innocent Bystander


Exp: 3 years



« Posted 2015-05-19 19:06:24 »

I used the code of the Getting Started Tutorial from this forum.

I only have one Problem i don't get it on how i can identify my buttons and sliders in the event queue.

Here is my sample code trying to use comp.getIdentifier().getName()

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  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
package org.maxbit.drone.skyhawkone;

import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Event;
import net.java.games.input.EventQueue;
import net.java.games.input.Version;

public class PilotMain {

   public static void main(String[] args) {
      Controller[] controllers = ControllerEnvironment
            .getDefaultEnvironment().getControllers();
      if (controllers.length == 0) {
         System.out.println("Found no controllers.");
         System.exit(0);
      }

      for (int i = 0; i < controllers.length; i++) {
         System.out.println(i+": "+controllers[i].getName());
      }
     
      int i = 1;
      System.out.println(controllers[i].getName());
     
      Component[] components = controllers[i].getComponents();
     
      while (true) {
         controllers[i].poll();
         EventQueue queue = controllers[i].getEventQueue();

         Event event = new Event();
         while (queue.getNextEvent(event)) {
            Component comp = event.getComponent();
   
            float value = event.getValue();
            switch(comp.getIdentifier().getName()) {
            case "Pinkie":
               if(value == 1.0f)
                  System.out.println("Trigger Flares!");
               break;
            case "Trigger":
               if(value == 1.0f)
                  System.out.println("Focuse  Camera1");
               break;
            case "Unknown":
               if(value == 1.0f) {
                  System.out.println("Trigger Camera1");
               }
               break;
            default:
               System.out.println(comp.getIdentifier().getName());
            }
//            if (comp.isAnalog()) {
//               ;
//            } else {
//               if (value == 1.0f) {
//                  System.out.println(comp.getName()+": ON");
//               } else {
//                  System.out.println(comp.getName()+": OFF");
//               }
//            }
         }

         try {
            Thread.sleep(20);
         } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }
   }
}


The problem here is that Unknown isn't unique also pov.
I am using a Saitek X52 Joystick.

Wish you all a nice day hope some one can help.
cheeĀ­rio from Austria Wink
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (13 views)
2017-11-21 16:21:00

xxMrPHDxx (10 views)
2017-11-21 16:14:31

xxMrPHDxx (10 views)
2017-11-21 16:10:57

Ecumene (113 views)
2017-09-30 02:57:34

theagentd (148 views)
2017-09-26 18:23:31

cybrmynd (246 views)
2017-08-02 12:28:51

cybrmynd (242 views)
2017-08-02 12:19:43

cybrmynd (242 views)
2017-08-02 12:18:09

Sralse (257 views)
2017-07-25 17:13:48

Archive (875 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!