本文整理汇总了Java中net.java.games.input.ControllerEnvironment类的典型用法代码示例。如果您正苦于以下问题:Java ControllerEnvironment类的具体用法?Java ControllerEnvironment怎么用?Java ControllerEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ControllerEnvironment类属于net.java.games.input包,在下文中一共展示了ControllerEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nativesTest
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
@Test
public void nativesTest() {
new NativeLibrary("jinput") //
.register(Platform.Windows_x86, "jinput-dx8.dll") //
.register(Platform.Windows_x86, "jinput-raw.dll") //
.register(Platform.Windows_x64, "jinput-dx8_64.dll") //
.register(Platform.Windows_x64, "jinput-raw_64.dll") //
.register(Platform.Linux_x86, "libjinput-linux.so") //
.register(Platform.Linux_x64, "libjinput-linux64.so") //
.register(Platform.MacOS, "libjinput-osx.jnilib") //
.require(true) //
.deleteOnExit(true)//
.extractTo(new File("target", "jinput-natives")) //
.load(Loaders.JAVA_LIBRARY_PATH__LOADER);
final Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
assertTrue(controllers.length > 0);
for (final Controller controller : controllers) {
System.out.println(controller.getName());
}
}
示例2: GamepadHandler
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public GamepadHandler()
{
ArrayList<Controller> controllers = new ArrayList<Controller>(Arrays.asList(ControllerEnvironment.getDefaultEnvironment().getControllers()));
Controller current;
for (int i=0;i<controllers.size();i++)
{
current = controllers.get(i);
if (current.getType() == Controller.Type.GAMEPAD || current.getType() == Controller.Type.STICK)
m_GamePads.add(new Gamepad(current));
else
controllers.remove(i--);
}
//m_JInputControllerHandles = controllers.toArray(new net.java.games.input.Controller[controllers.size()]);
}
示例3: getButtonController
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Description of the Method
*
* @param index Description of the Parameter
* @return Description of the Return Value
*/
public static int getButtonController(int index) {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
int controllerCount = 0;
for (int d = 0; d < cs.length; d++) {
Controller.Type type = cs[d].getType();
if ((type == Controller.Type.GAMEPAD) || (type == Controller.Type.STICK) || cs[d].getName().toLowerCase().contains("wiimote") || cs[d].getName().toLowerCase().contains("shuttle")) {
if (controllerCount == index) {
return d;
}
controllerCount++;
}
}
return -1;
}
示例4: getButton
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Gets the button attribute of the YassInput class
*
* @param d Description of the Parameter
* @param i Description of the Parameter
* @return The button value
*/
public static int getButton(int d, int i) {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
int buttonCount = 0;
Component[] comps = cs[d].getComponents();
for (int c = 0; c < comps.length; c++) {
if (!(comps[c].getIdentifier() instanceof Component.Identifier.Axis)) {
if (buttonCount == i) {
return c;
}
buttonCount++;
}
}
return -1;
}
示例5: pollAllButtons
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Description of the Method
*/
public void pollAllButtons() {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
for (Controller cc : cs) {
Controller.Type type = cc.getType();
//if (type == Controller.Type.MOUSE || type == Controller.Type.KEYBOARD) {
// continue;
//} else
if (type == Controller.Type.GAMEPAD || type == Controller.Type.STICK) {
cc.poll();
} else if (type == Controller.Type.UNKNOWN) {
cc.poll();
} else if (cc.getName().toLowerCase().contains("wiimote")) {
cc.poll();
}
}
}
示例6: rediscoverJoysticks
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public static Map<String, ControllerConfiguration> rediscoverJoysticks()
{
Controller[] availableControllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
Map<String, ControllerConfiguration> controllerConfig = new LinkedHashMap<>();
Map<String, Integer> deviceCounter = new LinkedHashMap<>();
controllerConfig.clear();
for (Controller controller : availableControllers)
{
if (sTYPES_TO_IGNORE.contains(controller.getType()))
{
continue;
}
Class<? extends IMockJoystick> specializationClass = getDefaultSpecialization(controller);
int deviceCtr = deviceCounter.getOrDefault(controller.getName(), 0);
deviceCounter.put(controller.getName(), ++deviceCtr);
String deviceName = controller.getName() + " " + deviceCtr;
ControllerConfiguration configuration = new ControllerConfiguration(controller, specializationClass);
controllerConfig.put(deviceName, configuration);
}
return sort(controllerConfig);
}
示例7: findGamepad
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public static Controller findGamepad() throws InterruptedException {
Controller instance;
do {
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
instance = Stream.of(controllers)
.filter(controller -> controller.getType() == GAMEPAD)
.findAny()
.orElseGet(() -> {
LOG.error("No controllers of type GAMEPAD found! Will retry in 5 sec");
return null;
});
if (instance == null) {
Thread.sleep(5000);
}
} while (instance == null);
LOG.info("Found a controller of type GAMEPAD: {}", instance);
return instance;
}
示例8: initKeyboard
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Init
*/
public static void initKeyboard() {
controllerEnvironment = ControllerEnvironment.getDefaultEnvironment();
controllers = controllerEnvironment.getControllers();
for(int i = 0; i < controllers.length; i++) {
Controller c = controllers[i];
if((c.getType() == Controller.Type.KEYBOARD) && (c instanceof Keyboard)) {
if(NullpoMinoSlick.useJInputKeyboard) {
log.debug("initKeyboard: Keyboard found");
}
keyboard = (Keyboard)c;
}
}
if((keyboard == null) && (NullpoMinoSlick.useJInputKeyboard)) {
log.error("initKeyboard: Keyboard NOT FOUND");
// Linux
if(System.getProperty("os.name").startsWith("Linux")) {
log.error("If you can use sudo, try the following command and start NullpoMino again:");
log.error("sudo chmod go+r /dev/input/*");
}
}
}
示例9: JoystickHandler
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public JoystickHandler()
{
connectBuffer();
Controller[] ca = ControllerEnvironment.getDefaultEnvironment()
.getControllers();
// find the joystick
for (int i = 0; i < ca.length; i++)
{
if (ca[i].getType() ==Controller.Type.STICK )
{
joystick = ca[i];
x_axis = joystick.getComponent(Component.Identifier.Axis.X);
landButton = joystick.getComponent(Component.Identifier.Button.TRIGGER);
}
}
}
示例10: updateControllers
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public void updateControllers() {
mousecontrollers.clear();
keyboardcontrollers.clear();
gamepadcontrollers.clear();
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
for (Controller c : ca) {
Type t = c.getType();
if (t == Type.MOUSE)
mousecontrollers.add((Mouse) c);
if (t == Type.KEYBOARD)
keyboardcontrollers.add((Keyboard) c);
if (t == Type.GAMEPAD)
gamepadcontrollers.add(c);
}
}
示例11: updateGamepads
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
private void updateGamepads() {
this.handleHotPluggedControllers = true;
try {
this.hackTheShitOutOfJInputBecauseItSucksHard();
// update plugged in gamepads
for (int i = 0; i < ControllerEnvironment.getDefaultEnvironment().getControllers().length; i++) {
final Controller controller = ControllerEnvironment.getDefaultEnvironment().getControllers()[i];
final Type type = controller.getType();
if (!type.equals(Type.GAMEPAD)) {
continue;
}
final IGamepad existing = Input.getGamepad(i);
if (existing != null && existing.getName().equals(controller.getName())) {
// already added
continue;
}
// add new gamepads
final IGamepad newGamepad = new Gamepad(i, controller);
Input.gamepads().add(newGamepad);
for (final Consumer<IGamepad> cons : this.gamepadAddedConsumer) {
cons.accept(newGamepad);
}
}
} catch (IllegalStateException e) {
this.loop.terminate();
} finally {
this.handleHotPluggedControllers = false;
}
}
示例12: init
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Description of the Method
*/
public static void init() {
try {
// JInput bug: list is never refreshed
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
ce.getControllers();
} catch (java.lang.UnsatisfiedLinkError e) {
System.out.println("No jinput-raw in java.library.path");
}
}
示例13: getControllerIndex
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Gets the controllerIndex attribute of the YassInput object
*
* @param s Description of the Parameter
* @return The controllerIndex value
*/
public int getControllerIndex(String s) {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
for (int d = 0; d < cs.length; d++) {
if (cs[d].getName().equals(s)) {
return d;
}
}
return -1;
}
示例14: getController
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Gets the controller attribute of the YassInput object
*
* @param s Description of the Parameter
* @return The controller value
*/
public Controller getController(String s) {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
for (Controller c : cs) {
if (c.getName().equals(s)) {
return c;
}
}
return null;
}
示例15: getComponentIndex
import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
* Gets the componentIndex attribute of the YassInput object
*
* @param d Description of the Parameter
* @param s Description of the Parameter
* @return The componentIndex value
*/
public int getComponentIndex(int d, String s) {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
Component[] comps = cs[d].getComponents();
for (int c = 0; c < comps.length; c++) {
if (comps[c].getName().equals(s)) {
return c;
}
}
return -1;
}