Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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 1768 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  
 
 

 
hadezbladez (289 views)
2018-11-16 13:46:03

hadezbladez (157 views)
2018-11-16 13:41:33

hadezbladez (290 views)
2018-11-16 13:35:35

hadezbladez (71 views)
2018-11-16 13:32:03

EgonOlsen (2150 views)
2018-06-10 19:43:48

EgonOlsen (2152 views)
2018-06-10 19:43:44

EgonOlsen (1364 views)
2018-06-10 19:43:20

DesertCoockie (1983 views)
2018-05-13 18:23:11

nelsongames (1601 views)
2018-04-24 18:15:36

nelsongames (2248 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!