jinput-20100502/0000755000175000017500000000000011367367574013237 5ustar twernertwernerjinput-20100502/applet/0000755000175000017500000000000011367367552014520 5ustar twernertwernerjinput-20100502/applet/jinput-event.html0000644000175000017500000000124211161526501020014 0ustar twernertwerner JInput Applet Test jinput-20100502/applet/src/0000755000175000017500000000000011367367552015307 5ustar twernertwernerjinput-20100502/applet/src/net/0000755000175000017500000000000011367367552016075 5ustar twernertwernerjinput-20100502/applet/src/net/java/0000755000175000017500000000000011367367552017016 5ustar twernertwernerjinput-20100502/applet/src/net/java/games/0000755000175000017500000000000011367367552020112 5ustar twernertwernerjinput-20100502/applet/src/net/java/games/input/0000755000175000017500000000000011367367552021251 5ustar twernertwernerjinput-20100502/applet/src/net/java/games/input/applet/0000755000175000017500000000000011367367552022536 5ustar twernertwernerjinput-20100502/applet/src/net/java/games/input/applet/JInputAppletResourceLoader.java0000644000175000017500000001762511107373400030607 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input.applet; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; public class JInputAppletResourceLoader { private static final Logger diagnosticLog = Logger.getLogger(JInputAppletResourceLoader.class.getName()); private int percentageDone = 0; private String getPrivilegedProperty(final String property) { return (String) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property); } }); } private String setPrivilegedProperty(final String property, final String value) { return (String) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.setProperty(property, value); } }); } public void loadResources(URL codeBase) throws IOException { downloadNativesJar(codeBase); extractNativesJar(codeBase); setJInputClasspath(codeBase); } public int getPercentageDone() { return percentageDone; } private void setJInputClasspath(URL codeBase) { setPrivilegedProperty("net.java.games.input.librarypath", getTempDir(codeBase) + File.separator + "natives" + File.separator); } private void extractNativesJar(URL codeBase) throws IOException { File tempDir = new File(getTempDir(codeBase)); String osName = getPrivilegedProperty("os.name"); String nativeJar = null; if (osName.startsWith("Win")) { nativeJar = "jinput-windows-native.jar"; } else if (osName.startsWith("Linux") || osName.startsWith("FreeBSD")) { nativeJar = "jinput-linux-native.jar"; } else if (osName.startsWith("Mac")) { nativeJar = "jinput-osx-native.jar"; } else { } JarFile localJarFile = new JarFile(new File(tempDir, nativeJar), true); Enumeration jarEntries = localJarFile.entries(); int totalUncompressedBytes = 0; int totalUncompressedBytesWritten = 0; List entriesToUse = new ArrayList(); while(jarEntries.hasMoreElements()) { JarEntry jarEntry = (JarEntry)jarEntries.nextElement(); String entryName = jarEntry.getName(); if(!entryName.startsWith("META-INF")) { totalUncompressedBytes+=jarEntry.getSize(); entriesToUse.add(jarEntry); diagnosticLog.log(Level.INFO, "Got entry " + entryName + " " + jarEntry.getSize() + " big, total of " + totalUncompressedBytes); } } File tempNativesDir = new File(tempDir, "natives"); if(!tempNativesDir.exists()) { tempNativesDir.mkdirs(); tempNativesDir.deleteOnExit(); } for(int i=0;i JInput Applet Test jinput-20100502/applet/build.xml0000644000175000017500000000253011161526537016331 0ustar twernertwerner jinput-20100502/lib/0000755000175000017500000000000011367367574014005 5ustar twernertwernerjinput-20100502/webstart/0000755000175000017500000000000011367367574015072 5ustar twernertwernerjinput-20100502/webstart/jinput.jnlp0000644000175000017500000000214710521207273017250 0ustar twernertwerner JInput webstart demo New Dawn Software The readtest demo from jinput as a webstartable demo JInput JWS demo jinput-20100502/webstart/build.xml0000644000175000017500000000250011164510353016664 0ustar twernertwerner jinput-20100502/webstart/jinput-wintab.jnlp0000644000175000017500000000231410521207273020526 0ustar twernertwerner JInput webstart demo New Dawn Software The readtest demo from jinput as a webstartable demo JInput JWS demo jinput-20100502/README.txt0000644000175000017500000000713510524355323014722 0ustar twernertwernerProject: net.java.games.* Purpose: Open source game libraries Authors: -- input API design: Michael Martak, Sun Microsystems Thomas Daniel, Sony Computer Entertainment -- input API original author: Michael Martak,Sun Microsystems -- input API original release author: Jeff Kesselman, Game Technology Architect, Advanced Software Technologies Group, Sun Microsystems. -- this file updated on 06/06/2003 by Jeff Kesselman Introduction: This is the source tree for the Java Game Initiative (JGI) Open Source client game programming APIs. Build Requirements: Note: This build depends on there being a jutils.jar in the lib directories of both the coreAPI and the plug-ins. If you install the JGI Jutils project at the same root as this project and build it first it will put jars in the right places. This project has been built in the following environment. -- Win32 (Win 2000 in the case of our machine) -- Sun J2SDK 1.4 (available at java.sun.com) -- MinGW 2.0.0 plus the following updates: (all available at www.mingw.org) -- binutils 2.13.90 -- w32api-2.2 -- mingw-runtime-2.4 -- "Peter Puck's" directx8 binding (http://www.urebelscum.speedhost.com/download.html, file: dx8libs.zip (Copy all of his *.a library files into the MingW "lib" directory) -- The DirectX 9 SDK available at the Microsoft DirectX site. (http://www.microsoft.com/directx) The Win32 plug-in build.xml file expects this to be installed in c:\dx9. You can install it elsewhere but then you will have to modify the reference in that build.xml ant script. -- ANT 1.4.1 (available at apache.org) Directory Organization: The root contains a master ANT build.xml and the following sub directories: -- coreAPI: The actual API -- plugins: Directories for building controller plugins. (Currently the only plug in is the Win32 DX8 plugin.) Build instructions: To clean: ant clean To build: ant all (or just ant) To build docs: ant javadoc To test: First cd to coreAPI. There are currently 2 tests there. Textest: A simple discovery test that dumps the data about the discovered controllers to stdout To run: ant textest Readtest: A test that creates a window for each discovered controller (or sub-controller) which displays the current state of all the controller's axes. (Note: The windows currently all open at the same place on the screen so you will have to move them to see them all.) To run: ant readtest Release Info: Initial Release: This release contains an implementation of the input API designed by Mike Martak of Sun and Thomas (?) of Sony CEA for the WIn32 platform. All the code in src/input is cross platform. The Win32 code is segregated to the DirectX plugin (src/DXplugin) which depends on DirectInput from DX7 (or later). 05/09/2003: A number of bugs and problems with the DXPlugin are fixed in this release. This release also brings the code up to date using the DI8 interface. This thus is the first release that requires Peter Puck's DX8 bindings to compile with MinGW. 05/09/2003 (second update): This version adds a new standard value type to the API. Axis.POV holds standard definitions for values for POV (hat) switches -- Axis.POV.CENTER and Axis.POV.OFF are synonymous and are the center position. -- Axis.POV.UP, Axis.POV.DOWN, Axis.POV.LEFT and Axis.POV.RIGHT should be self explanatory. Any hat that claims to be "normalized" will return these values. (It is recommended that all hats be normalized by the system specific plugins.) jinput-20100502/coreAPI/0000755000175000017500000000000011367367552014515 5ustar twernertwernerjinput-20100502/coreAPI/README.txt0000644000175000017500000000415407670200706016204 0ustar twernertwernerThis file modified last on 06/06/2003 by Jeff Kesselman This is the source tree for the core input API. Directory Organization: The root contains a master ANT build.xml. After a successful build of the project you will have the following sub directories: -- apidocs Where the javadocs get built to -- lib Where dependant libraries are kept. -- bin Where the actual API is built to -- src The source files. -- src/test Execution directories and data for tests. Build instructions: To clean: ant clean To build: ant all (or just ant) To build docs: ant javadoc To test: Textest: A simple discovery test that dumps the data about the discovered controllers to stdout To run: ant textest Readtest: A test that creates a window for each discovered controller (or sub-controller) which displays the current state of all the controller's axiis. (Note: The windows currrently all open at the same place on the screen so yo uwill have to move them to see them all.) To run: ant readtest Release Info: Initial Release: This release contains an implementation of the input API designed by Mike Martak of Sun and Thomas (?) of Sony CEA for the WIn32 platform. All the code in src/input is cross platform. The Win32 code is segregated to the DirectX plugin (src/DXplugin) which depends on DirectInput from DX7 (or later). 05/09/2003: A number of bugs and problems with the DXPlugin are fixed in this release. This release also brings the code up to date using the DI8 interface. This thus is the first release that requries Peter Puck's DX8 bindings to compile with MinGW. 05/09/2003 (second update): This version adds a new standard value type to the API. Axis.POV holds standard definitions for values for POV (hat) switches -- Axis.POV.CENTER and Axis.POV.OFF are synonmous and are the center position. -- Axis.POV.UP, Axis.POV.DOWN, Axis.POV.LEFT and Axis.POV.RIGHT should be self explainatory. Any hat that claims to be "normalized" will return these values. (It is recommended that all hats be normalized by the systemn specific plugins.) jinput-20100502/coreAPI/src/0000755000175000017500000000000011367367552015304 5ustar twernertwernerjinput-20100502/coreAPI/src/java/0000755000175000017500000000000011367367552016225 5ustar twernertwernerjinput-20100502/coreAPI/src/java/net/0000755000175000017500000000000011367367552017013 5ustar twernertwernerjinput-20100502/coreAPI/src/java/net/java/0000755000175000017500000000000011367367552017734 5ustar twernertwernerjinput-20100502/coreAPI/src/java/net/java/games/0000755000175000017500000000000011367367552021030 5ustar twernertwernerjinput-20100502/coreAPI/src/java/net/java/games/input/0000755000175000017500000000000011367367553022170 5ustar twernertwernerjinput-20100502/coreAPI/src/java/net/java/games/input/ControllerListener.java0000644000175000017500000000467507670200706026664 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * A listener for changes in the state of controllers */ public interface ControllerListener { /** * Invoked when a controller is lost. */ public abstract void controllerRemoved(ControllerEvent ev); /** * Invoked when a controller has been added. */ public abstract void controllerAdded(ControllerEvent ev); } // interface ControllerListener jinput-20100502/coreAPI/src/java/net/java/games/input/EventQueue.java0000644000175000017500000000531310424764250025107 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; public final class EventQueue { private final Event[] queue; private int head; private int tail; public EventQueue(int size) { queue = new Event[size + 1]; for (int i = 0; i < queue.length; i++) queue[i] = new Event(); } final synchronized void add(Event event) { queue[tail].set(event); tail = increase(tail); } final synchronized boolean isFull() { return increase(tail) == head; } private final int increase(int x) { return (x + 1)%queue.length; } public final synchronized boolean getNextEvent(Event event) { if (head == tail) return false; event.set(queue[head]); head = increase(head); return true; } } jinput-20100502/coreAPI/src/java/net/java/games/input/Keyboard.java0000644000175000017500000000570010424764247024567 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * A Keyboard is a type of controller consisting of a single controller, * they keypad, which contains several axes (the keys). By default, all keys * are set to receive polling data. */ public abstract class Keyboard extends AbstractController { /** * Protected constructor. * Subclasses should initialize the array of axes to an array of keys. * @param name The name of the keyboard */ protected Keyboard(String name, Component[] keys, Controller[] children, Rumbler[] rumblers) { super(name, keys, children, rumblers); } /** * Returns the type of the Controller. */ public Type getType() { return Type.KEYBOARD; } public final boolean isKeyDown(Component.Identifier.Key key_id) { Component key = getComponent(key_id); if (key == null) return false; return key.getPollData() != 0; } } // class Keyboard jinput-20100502/coreAPI/src/java/net/java/games/input/AbstractComponent.java0000644000175000017500000001106410710600327026437 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** * Skeleton implementation of a named axis. */ public abstract class AbstractComponent implements Component { /** * Human-readable name for this Axis */ private final String name; private final Identifier id; private boolean has_polled; private float value; private float event_value; /** * Protected constructor * @param name A name for the axis */ protected AbstractComponent(String name, Identifier id) { this.name = name; this.id = id; } /** * Returns the type or identifier of the axis. */ public Identifier getIdentifier() { return id; } /** * Returns whether or not the axis is analog, or false if it is digital. * @return false by default, can be overridden */ public boolean isAnalog() { return false; } /** * Returns the suggested dead zone for this axis. Dead zone is the * amount polled data can vary before considered a significant change * in value. An application can safely ignore changes less than this * value in the positive or negative direction. * @return 0.0f by default, can be overridden */ public float getDeadZone() { return 0.0f; } /** * Returns the data from the last time the control has been polled. * If this axis is a button, the value returned will be either 0.0f or 1.0f. * If this axis is normalised, the value returned will be between -1.0f and * 1.0f. * @return The data from the last time the control has been polled. */ public final float getPollData() { if (!has_polled && !isRelative()) { has_polled = true; try { setPollData(poll()); } catch (IOException e) { ControllerEnvironment.log("Failed to poll component: " + e); } } return value; } final void resetHasPolled() { has_polled = false; } final void setPollData(float value) { this.value = value; } final float getEventValue() { return event_value; } final void setEventValue(float event_value) { this.event_value = event_value; } /** * Returns a human-readable name for this axis. */ public String getName() { return name; } /** * Returns a non-localized string description of this axis. */ public String toString() { return name; } protected abstract float poll() throws IOException; } // AbstractAxis jinput-20100502/coreAPI/src/java/net/java/games/input/test/0000755000175000017500000000000011367367553023147 5ustar twernertwernerjinput-20100502/coreAPI/src/java/net/java/games/input/test/RumbleTest.java0000644000175000017500000000464410716405433026073 0ustar twernertwerner/* * RumbleTest.java * * Created on 01 December 2003, 23:02 */ package net.java.games.input.test; import net.java.games.input.ControllerEnvironment; import net.java.games.input.Controller; import net.java.games.input.Rumbler; /** * * @author Jeremy */ public class RumbleTest { /** Creates a new instance of RumbleTest */ public RumbleTest() { ControllerEnvironment ca = ControllerEnvironment.getDefaultEnvironment(); Controller[] controllers = ca.getControllers(); for(int i=0;i-1.0f;) { long startTime = System.currentTimeMillis(); rumblers[j].rumble(k); try { Thread.sleep(1); } catch (InterruptedException e) { } k-=((float)(System.currentTimeMillis() - startTime))/1000f; } try { Thread.sleep(1000); } catch (InterruptedException e) { } System.out.println("Rumbling with intensity: " + 0.0f); rumblers[j].rumble(0f); try { Thread.sleep(1000); } catch (InterruptedException e) { } } } System.exit(0); } /** * @param args the command line arguments */ public static void main(String[] args) { new RumbleTest(); } } jinput-20100502/coreAPI/src/java/net/java/games/input/test/ControllerReadTest.java0000644000175000017500000002116210446743344027564 0ustar twernertwerner/* * ConrtollerReadTest.java * * Created on May 5, 2003, 3:15 PM */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input.test; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.GridLayout; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import net.java.games.input.Component; import net.java.games.input.Controller; import net.java.games.input.ControllerEnvironment; public class ControllerReadTest extends JFrame{ private abstract static class AxisPanel extends JPanel{ Component axis; float data; public AxisPanel(Component ax){ axis = ax; setLayout(new BorderLayout()); add(new JLabel(ax.getName()+"("+ax.getIdentifier()+")"), BorderLayout.NORTH); } public void poll(){ data = axis.getPollData(); renderData(); } public Component getAxis() { return axis; } protected abstract void renderData(); } private static class DigitalAxisPanel extends AxisPanel { JLabel digitalState = new JLabel(""); public DigitalAxisPanel(Component ax) { super(ax); add(digitalState,BorderLayout.CENTER); } protected void renderData(){ if (data == 0.0f){ digitalState.setBackground(getBackground()); digitalState.setText("OFF"); } else if ( data == 1.0f) { digitalState.setBackground(Color.green); digitalState.setText("ON"); }else { // shoudl never happen digitalState.setBackground(Color.red); digitalState.setText("ERR:"+data); } digitalState.repaint(); } } private static class DigitalHatPanel extends AxisPanel { JLabel digitalState = new JLabel(""); public DigitalHatPanel(Component ax) { super(ax); add(digitalState,BorderLayout.CENTER); } protected void renderData(){ if (data == Component.POV.OFF){ digitalState.setBackground(getBackground()); digitalState.setText("OFF"); } else if ( data == Component.POV.UP) { digitalState.setBackground(Color.green); digitalState.setText("UP"); } else if ( data == Component.POV.UP_RIGHT) { digitalState.setBackground(Color.green); digitalState.setText("UP+RIGHT"); } else if ( data == Component.POV.RIGHT) { digitalState.setBackground(Color.green); digitalState.setText("RIGHT"); } else if ( data == Component.POV.DOWN_RIGHT) { digitalState.setBackground(Color.green); digitalState.setText("DOWN+RIGHT"); } else if ( data == Component.POV.DOWN) { digitalState.setBackground(Color.green); digitalState.setText("DOWN"); } else if ( data == Component.POV.DOWN_LEFT) { digitalState.setBackground(Color.green); digitalState.setText("DOWN+LEFT"); } else if ( data == Component.POV.LEFT) { digitalState.setBackground(Color.green); digitalState.setText("LEFT"); } else if ( data == Component.POV.UP_LEFT) { digitalState.setBackground(Color.green); digitalState.setText("UP+LEFT"); }else { // shoudl never happen digitalState.setBackground(Color.red); digitalState.setText("ERR:"+data); } digitalState.repaint(); } } private static class AnalogAxisPanel extends AxisPanel { JLabel analogState = new JLabel(""); public AnalogAxisPanel(Component ax) { super(ax); add(analogState,BorderLayout.CENTER); } protected void renderData(){ String extra = ""; if (getAxis().getDeadZone() >= Math.abs(data)) extra = " (DEADZONE)"; analogState.setText(""+data+extra); analogState.repaint(); } } private static class ControllerWindow extends JFrame { Controller ca; List axisList = new ArrayList(); boolean disabled = false; public ControllerWindow(JFrame frame,Controller ca){ super(ca.getName()); this.setName(ca.getName()); this.ca = ca; Container c = this.getContentPane(); c.setLayout(new BorderLayout()); Component[] components = ca.getComponents(); System.out.println("Component count = "+components.length); if (components.length>0) { int width = (int)Math.ceil(Math.sqrt(components.length)); JPanel p = new JPanel(); p.setLayout(new GridLayout(width,0)); for(int j=0;j"); public DigitalAxisPanel(Component ax) { super(ax); add(digitalState,BorderLayout.CENTER); } protected void renderData(){ if (data == 0.0f){ digitalState.setBackground(getBackground()); digitalState.setText("OFF"); } else if ( data == 1.0f) { digitalState.setBackground(Color.green); digitalState.setText("ON"); }else { // shoudl never happen digitalState.setBackground(Color.red); digitalState.setText("ERR:"+data); } digitalState.repaint(); } } private static class DigitalHatPanel extends AxisPanel { JLabel digitalState = new JLabel(""); public DigitalHatPanel(Component ax) { super(ax); add(digitalState,BorderLayout.CENTER); } protected void renderData(){ if (data == Component.POV.OFF){ digitalState.setBackground(getBackground()); digitalState.setText("OFF"); } else if ( data == Component.POV.UP) { digitalState.setBackground(Color.green); digitalState.setText("UP"); } else if ( data == Component.POV.UP_RIGHT) { digitalState.setBackground(Color.green); digitalState.setText("UP+RIGHT"); } else if ( data == Component.POV.RIGHT) { digitalState.setBackground(Color.green); digitalState.setText("RIGHT"); } else if ( data == Component.POV.DOWN_RIGHT) { digitalState.setBackground(Color.green); digitalState.setText("DOWN+RIGHT"); } else if ( data == Component.POV.DOWN) { digitalState.setBackground(Color.green); digitalState.setText("DOWN"); } else if ( data == Component.POV.DOWN_LEFT) { digitalState.setBackground(Color.green); digitalState.setText("DOWN+LEFT"); } else if ( data == Component.POV.LEFT) { digitalState.setBackground(Color.green); digitalState.setText("LEFT"); } else if ( data == Component.POV.UP_LEFT) { digitalState.setBackground(Color.green); digitalState.setText("UP+LEFT"); }else { // shoudl never happen digitalState.setBackground(Color.red); digitalState.setText("ERR:"+data); } digitalState.repaint(); } } private static class AnalogAxisPanel extends AxisPanel { JLabel analogState = new JLabel(""); public AnalogAxisPanel(Component ax) { super(ax); add(analogState,BorderLayout.CENTER); } protected void renderData(){ String extra = ""; if (getAxis().getDeadZone() >= Math.abs(data)) extra = " (DEADZONE)"; analogState.setText(""+data+extra); analogState.repaint(); } } private static class ControllerWindow extends JFrame { Controller ca; Map axes_to_panels = new HashMap(); boolean disabled = false; public ControllerWindow(JFrame frame,Controller ca){ super(ca.getName()); this.setName(ca.getName()); this.ca = ca; Container c = this.getContentPane(); c.setLayout(new BorderLayout()); Component[] components = ca.getComponents(); System.out.println("Component count = "+components.length); if (components.length>0) { int width = (int)Math.ceil(Math.sqrt(components.length)); JPanel p = new JPanel(); p.setLayout(new GridLayout(width,0)); for(int j=0;j Top level package for JInput.

Package Specification

Use -Djinput.useDefaultPlugin=false (or net.java.games.input.useDefaultPlugin=false) to disable automatic loading of the default plugin for the platform.
Use -Djinput.plugins (or net.java.games.input.plugins) and specifiy a list of class name to over ride the plugins system. This will force the classes passed to be loaded first, then plugins will be searched for in the default manner (./controller/*.jar)
Use -Djinput.controllerPluginPath to change the path the plugins mechanism will use to search for plugin Jars. jinput-20100502/coreAPI/src/java/net/java/games/input/PluginClassLoader.java0000644000175000017500000001454010041441605026365 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.StringTokenizer; import java.util.jar.JarEntry; import java.util.jar.JarFile; /** * Loads all plugins. * * @version %I% %G% * @author Michael Martak */ class PluginClassLoader extends ClassLoader { /** * Location of directory to look for plugins */ private static String pluginDirectory; /** * File filter for JAR files */ private static final FileFilter JAR_FILTER = new JarFileFilter(); /** * Create a new class loader for loading plugins */ public PluginClassLoader() { super(Thread.currentThread().getContextClassLoader()); } /** * Overrides findClass to first look in the parent class loader, * then try loading the class from the plugin file system. */ protected Class findClass(String name) throws ClassNotFoundException { // Try loading the class from the file system. byte[] b = loadClassData(name); return defineClass(name, b, 0, b.length); } /** * Load the class data from the file system */ private byte[] loadClassData(String name) throws ClassNotFoundException { if (pluginDirectory == null) { pluginDirectory = DefaultControllerEnvironment.libPath + File.separator + "controller"; } try { return loadClassFromDirectory(name); } catch (Exception e) { try { return loadClassFromJAR(name); } catch (IOException e2) { throw new ClassNotFoundException(name, e2); } } } /** * Load the class data from the file system based on parsing * the class name (packages). */ private byte[] loadClassFromDirectory(String name) throws ClassNotFoundException, IOException { // Parse the class name into package directories. // Look for the class in the plugin directory. StringTokenizer tokenizer = new StringTokenizer(name, "."); StringBuffer path = new StringBuffer(pluginDirectory); while (tokenizer.hasMoreTokens()) { path.append(File.separator); path.append(tokenizer.nextToken()); } path.append(".class"); File file = new File(path.toString()); if (!file.exists()) { throw new ClassNotFoundException(name); } FileInputStream fileInputStream = new FileInputStream(file); assert file.length() <= Integer.MAX_VALUE; int length = (int)file.length(); byte[] bytes = new byte[length]; int length2 = fileInputStream.read(bytes); assert length == length2; return bytes; } /** * Scans through the plugin directory for JAR files and * attempts to load the class data from each JAR file. */ private byte[] loadClassFromJAR(String name) throws ClassNotFoundException, IOException { File dir = new File(pluginDirectory); File[] jarFiles = dir.listFiles(JAR_FILTER); if (jarFiles == null) { throw new ClassNotFoundException("Could not find class " + name); } for (int i = 0; i < jarFiles.length; i++) { JarFile jarfile = new JarFile(jarFiles[i]); JarEntry jarentry = jarfile.getJarEntry(name + ".class"); if (jarentry != null) { InputStream jarInputStream = jarfile.getInputStream(jarentry); assert jarentry.getSize() <= Integer.MAX_VALUE; int length = (int)jarentry.getSize(); assert length >= 0; byte[] bytes = new byte[length]; int length2 = jarInputStream.read(bytes); assert length == length2; return bytes; } } throw new FileNotFoundException(name); } /** * Filters out all non-JAR files, based on whether or not they * end in ".JAR" (case-insensitive). */ private static class JarFileFilter implements FileFilter { public boolean accept(File file) { return file.getName().toUpperCase().endsWith(".JAR"); } } } jinput-20100502/coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java0000644000175000017500000002200111273015044030660 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Properties; import java.util.StringTokenizer; import java.util.logging.Logger; import net.java.games.util.plugins.*; /** * The default controller environment. * * @version %I% %G% * @author Michael Martak */ class DefaultControllerEnvironment extends ControllerEnvironment { static String libPath; private static Logger log = Logger.getLogger(DefaultControllerEnvironment.class.getName()); /** * Static utility method for loading native libraries. * It will try to load from either the path given by * the net.java.games.input.librarypath property * or through System.loadLibrary(). * */ static void loadLibrary(final String lib_name) { AccessController.doPrivileged( new PrivilegedAction() { public final Object run() { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); else System.loadLibrary(lib_name); return null; } }); } static String getPrivilegedProperty(final String property) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property); } }); } static String getPrivilegedProperty(final String property, final String default_value) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property, default_value); } }); } /** * List of all controllers in this environment */ private ArrayList controllers; private Collection loadedPlugins = new ArrayList(); /** * Public no-arg constructor. */ public DefaultControllerEnvironment() { } /** * Returns a list of all controllers available to this environment, * or an empty array if there are no controllers in this environment. */ public Controller[] getControllers() { if (controllers == null) { // Controller list has not been scanned. controllers = new ArrayList(); AccessController.doPrivileged(new PrivilegedAction() { public Object run() { scanControllers(); return null; } }); //Check the properties for specified controller classes String pluginClasses = getPrivilegedProperty("jinput.plugins", "") + " " + getPrivilegedProperty("net.java.games.input.plugins", ""); if(!getPrivilegedProperty("jinput.useDefaultPlugin", "true").toLowerCase().trim().equals("false") && !getPrivilegedProperty("net.java.games.input.useDefaultPlugin", "true").toLowerCase().trim().equals("false")) { String osName = getPrivilegedProperty("os.name", "").trim(); if(osName.equals("Linux")) { pluginClasses = pluginClasses + " net.java.games.input.LinuxEnvironmentPlugin"; } else if(osName.equals("Mac OS X")) { pluginClasses = pluginClasses + " net.java.games.input.OSXEnvironmentPlugin"; } else if(osName.equals("Windows XP") || osName.equals("Windows Vista") || osName.equals("Windows 7")) { pluginClasses = pluginClasses + " net.java.games.input.DirectAndRawInputEnvironmentPlugin"; } else if(osName.equals("Windows 98") || osName.equals("Windows 2000")) { pluginClasses = pluginClasses + " net.java.games.input.DirectInputEnvironmentPlugin"; } else if (osName.startsWith("Windows")) { log.warning("Found unknown Windows version: " + osName); log.info("Attempting to use default windows plug-in."); pluginClasses = pluginClasses + " net.java.games.input.DirectAndRawInputEnvironmentPlugin"; } else { log.info("Trying to use default plugin, OS name " + osName +" not recognised"); } } StringTokenizer pluginClassTok = new StringTokenizer(pluginClasses, " \t\n\r\f,;:"); while(pluginClassTok.hasMoreTokens()) { String className = pluginClassTok.nextToken(); try { if(!loadedPlugins.contains(className)) { log.info("Loading: " + className); Class ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPlugins.add(ce.getClass().getName()); } else { logln(ceClass.getName() + " is not supported"); } } } catch (Throwable e) { e.printStackTrace(); } } } Controller[] ret = new Controller[controllers.size()]; Iterator it = controllers.iterator(); int i = 0; while (it.hasNext()) { ret[i] = (Controller)it.next(); i++; } return ret; } /* This is jeff's new plugin code using Jeff's Plugin manager */ private void scanControllers() { String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath"); if(pluginPathName == null) { pluginPathName = "controller"; } scanControllersAt(getPrivilegedProperty("java.home") + File.separator + "lib"+File.separator + pluginPathName); scanControllersAt(getPrivilegedProperty("user.dir")+ File.separator + pluginPathName); } private void scanControllersAt(String path) { File file = new File(path); if (!file.exists()) { return; } try { Plugins plugins = new Plugins(file); Class[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i *
  • * w - the major version number of the release. This number should * start at 1. Typically, a bump in the major version number * signifies that the release breaks backwards compatibility * with some older release. *
  • *
  • * x - minor version number. This number starts at 0. A bump in * the minor version number signifies a release that has significant * new functionality. *
  • *
  • * y - minor-minor version number number. This number starts at 0. A * bump in the minor-minor version number signifies that new bug * fixes have been added to the build. *
  • *
  • * a - an optional build designator followed by a digit. Valid build * designators are: *
      *
    • alpha
    • *
    • beta
    • *
    *
  • *
  • * z - build number. This is used to specify the build number of the * release. This is usually only important to people that use * the daily build of a project. The format is the lower-case * letter 'b' followed by a two digit number. *
  • * * * For example, the following are all valid version strings: *
      *
    • 1.1.2-b02
    • *
    • 1.3.5-alpha1-b19
    • *
    • 4.7.1-beta3-b20
    • *
    * */ public final class Version { /** * Private constructor - no need for user to create * an instance of this class. */ private Version() { } /** * Version string of this build. */ private static final String apiVersion = "2.0.1"; private static final String buildNumber = "@BUILD_NUMBER@"; /* * Split so that ant does not replace the token; */ private static final String antToken = "@BUILD_" + "NUMBER@"; /** * Returns the verison string and build number of * this implementation. See the class descritpion * for the version string format. * * @return The version string of this implementation. */ public static String getVersion() { String version = apiVersion; if(!antToken.equals(buildNumber)) { version += "-b" + buildNumber; } return version; } } jinput-20100502/coreAPI/src/java/net/java/games/input/Mouse.java0000644000175000017500000001317210641016004024077 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.util.List; import java.util.ArrayList; /** * A Mouse is a type of controller consisting of two child controllers, * a ball and a button pad. This includes devices such as touch pads, * trackballs, and fingersticks. */ public abstract class Mouse extends AbstractController { protected Mouse(String name, Component[] components, Controller[] children, Rumbler[] rumblers) { super(name, components, children, rumblers); } /** * Returns the type of the Controller. */ public Type getType() { return Type.MOUSE; } /** * Returns the x-axis for the mouse ball, never null. */ public Component getX() { return getComponent(Component.Identifier.Axis.X); } /** * Returns the y-axis for the mouse ball, never null. */ public Component getY() { return getComponent(Component.Identifier.Axis.Y); } /** * Returns the mouse wheel, or null if no mouse wheel is present. */ public Component getWheel() { return getComponent(Component.Identifier.Axis.Z); } /** * Returns the left or primary mouse button, never null. */ public Component getPrimaryButton() { Component primaryButton = getComponent(Component.Identifier.Button.LEFT); if(primaryButton==null) { primaryButton = getComponent(Component.Identifier.Button._1); } return primaryButton; } /** * Returns the right or secondary mouse button, null if the mouse is * a single-button mouse. */ public Component getSecondaryButton() { Component secondaryButton = getComponent(Component.Identifier.Button.RIGHT); if(secondaryButton==null) { secondaryButton = getComponent(Component.Identifier.Button._2); } return secondaryButton; } /** * Returns the middle or tertiary mouse button, null if the mouse has * fewer than three buttons. */ public Component getTertiaryButton() { Component tertiaryButton = getComponent(Component.Identifier.Button.MIDDLE); if(tertiaryButton==null) { tertiaryButton = getComponent(Component.Identifier.Button._3); } return tertiaryButton; } /** * Returns the left mouse button. */ public Component getLeft() { return getComponent(Component.Identifier.Button.LEFT); } /** * Returns the right, null if the mouse is a single-button mouse. */ public Component getRight() { return getComponent(Component.Identifier.Button.RIGHT); } /** * Returns the middle, null if the mouse has fewer than three buttons. */ public Component getMiddle() { return getComponent(Component.Identifier.Button.MIDDLE); } /** * Returns the side or 4th mouse button, null if the mouse has * fewer than 4 buttons. */ public Component getSide() { return getComponent(Component.Identifier.Button.SIDE); } /** * Returns the extra or 5th mouse button, null if the mouse has * fewer than 5 buttons. */ public Component getExtra() { return getComponent(Component.Identifier.Button.EXTRA); } /** * Returns the forward mouse button, null if the mouse hasn't * got one. */ public Component getForward() { return getComponent(Component.Identifier.Button.FORWARD); } /** * Returns the back mouse button, null if the mouse hasn't * got one. */ public Component getBack() { return getComponent(Component.Identifier.Button.BACK); } /** * Returns forth mouse button, null if the mouse hasn't * got one. */ public Component getButton3() { return getComponent(Component.Identifier.Button._3); } /** * Returns fifth mouse button, null if the mouse hasn't * got one. */ public Component getButton4() { return getComponent(Component.Identifier.Button._4); } } // class Mouse jinput-20100502/coreAPI/src/java/net/java/games/input/Rumbler.java0000644000175000017500000000523510114444303024422 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * A Rumbler is a controller's mechanism for delivering feedback * to the user through the device. */ public interface Rumbler { /** * Rumble with the specified intensity. */ public abstract void rumble(float intensity); /** * Get the string name of the axis the rumbler is attached to * * @return The axis name */ public String getAxisName(); /** * Get the axis identifier the rumbler is attached to * * @return The axis identifier */ public Component.Identifier getAxisIdentifier(); } // interface Rumbler jinput-20100502/coreAPI/src/java/net/java/games/input/example/0000755000175000017500000000000011367367553023623 5ustar twernertwernerjinput-20100502/coreAPI/src/java/net/java/games/input/example/ReadFirstMouse.java0000644000175000017500000000446110632753663027362 0ustar twernertwernerpackage net.java.games.input.example; import net.java.games.input.Component; import net.java.games.input.Controller; import net.java.games.input.ControllerEnvironment; import net.java.games.input.test.ControllerTextTest; /** * This class shows how to read the values in a polling loop for the first mouse * detected. It will show how to get the available controllers, how to check the * type of the controller, how to read the components of the controller, and how * to get the data from the component. * * @author Endolf */ public class ReadFirstMouse { public ReadFirstMouse() { /* Get the available controllers */ Controller[] controllers = ControllerEnvironment .getDefaultEnvironment().getControllers(); /* * Loop through the controllers, check the type of each one, and save * the first mouse we find. */ Controller firstMouse = null; for (int i = 0; i < controllers.length && firstMouse == null; i++) { if (controllers[i].getType() == Controller.Type.MOUSE) { // Found a mouse firstMouse = controllers[i]; } } if (firstMouse == null) { // Couldn't find a mouse System.out.println("Found no mouse"); System.exit(0); } System.out.println("First mouse is: " + firstMouse.getName()); while (true) { /* Poll the controller */ firstMouse.poll(); /* Get all the axis and buttons */ Component[] components = firstMouse.getComponents(); StringBuffer buffer = new StringBuffer(); /* For each component, get it's name, and it's current value */ for (int i = 0; i < components.length; i++) { if (i > 0) { buffer.append(", "); } buffer.append(components[i].getName()); buffer.append(": "); if (components[i].isAnalog()) { /* Get the value at the last poll of this component */ buffer.append(components[i].getPollData()); } else { if (components[i].getPollData() == 1.0f) { buffer.append("On"); } else { buffer.append("Off"); } } } System.out.println(buffer.toString()); /* * Sleep for 20 millis, this is just so the example doesn't thrash * the system. */ try { Thread.sleep(20); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String[] args) { new ReadFirstMouse(); } } jinput-20100502/coreAPI/src/java/net/java/games/input/example/ReadAllEvents.java0000644000175000017500000000503710632753663027157 0ustar twernertwernerpackage net.java.games.input.example; 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; /** * This class shows how to use the event queue system in JInput. It will show * how to get the controllers, how to get the event queue for a controller, and * how to read and process events from the queue. * * @author Endolf */ public class ReadAllEvents { public ReadAllEvents() { while (true) { /* Get the available controllers */ 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++) { /* Remember to poll each one */ controllers[i].poll(); /* Get the controllers event queue */ EventQueue queue = controllers[i].getEventQueue(); /* Create an event object for the underlying plugin to populate */ Event event = new Event(); /* For each object in the queue */ while (queue.getNextEvent(event)) { /* * Create a strug buffer and put in it, the controller name, * the time stamp of the event, the name of the component * that changed and the new value. * * Note that the timestamp is a relative thing, not * absolute, we can tell what order events happened in * across controllers this way. We can not use it to tell * exactly *when* an event happened just the order. */ StringBuffer buffer = new StringBuffer(controllers[i] .getName()); buffer.append(" at "); buffer.append(event.getNanos()).append(", "); Component comp = event.getComponent(); buffer.append(comp.getName()).append(" changed to "); float value = event.getValue(); /* * Check the type of the component and display an * appropriate value */ if (comp.isAnalog()) { buffer.append(value); } else { if (value == 1.0f) { buffer.append("On"); } else { buffer.append("Off"); } } System.out.println(buffer.toString()); } } /* * Sleep for 20 milliseconds, in here only so the example doesn't * thrash the system. */ try { Thread.sleep(20); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String[] args) { new ReadAllEvents(); } } jinput-20100502/coreAPI/src/java/net/java/games/input/AbstractController.java0000644000175000017500000001737410611654633026643 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.util.Map; import java.util.List; import java.util.HashMap; import java.util.ArrayList; import java.io.IOException; /** * An AbstractController is a skeleton implementation of a controller that * contains a fixed number of axes, controllers, and rumblers. */ public abstract class AbstractController implements Controller { final static int EVENT_QUEUE_DEPTH = 32; private final static Event event = new Event(); /** * Human-readable name for this Controller */ private final String name; /** * Array of components */ private final Component[] components; /** * Array of child controllers */ private final Controller[] children; /** * Array of rumblers */ private final Rumbler[] rumblers; /** * Map from Component.Identifiers to Components */ private final Map id_to_components = new HashMap(); private EventQueue event_queue = new EventQueue(EVENT_QUEUE_DEPTH); /** * Protected constructor for a controller containing the specified * axes, child controllers, and rumblers * @param name name for the controller * @param components components for the controller * @param children child controllers for the controller * @param rumblers rumblers for the controller */ protected AbstractController(String name, Component[] components, Controller[] children, Rumbler[] rumblers) { this.name = name; this.components = components; this.children = children; this.rumblers = rumblers; // process from last to first to let earlier listed Components get higher priority for (int i = components.length - 1; i >= 0; i--) { id_to_components.put(components[i].getIdentifier(), components[i]); } } /** * Returns the controllers connected to make up this controller, or * an empty array if this controller contains no child controllers. * The objects in the array are returned in order of assignment priority * (primary stick, secondary buttons, etc.). */ public final Controller[] getControllers() { return children; } /** * Returns the components on this controller, in order of assignment priority. * For example, the button controller on a mouse returns an array containing * the primary or leftmost mouse button, followed by the secondary or * rightmost mouse button (if present), followed by the middle mouse button * (if present). * The array returned is an empty array if this controller contains no components * (such as a logical grouping of child controllers). */ public final Component[] getComponents() { return components; } /** * Returns a single component based on its identifier, or null * if no component with the specified type could be found. */ public final Component getComponent(Component.Identifier id) { return (Component)id_to_components.get(id); } /** * Returns the rumblers for sending feedback to this controller, or an * empty array if there are no rumblers on this controller. */ public final Rumbler[] getRumblers() { return rumblers; } /** * Returns the port type for this Controller. * @return PortType.UNKNOWN by default, can be overridden */ public PortType getPortType() { return PortType.UNKNOWN; } /** * Returns the zero-based port number for this Controller. * @return 0 by default, can be overridden */ public int getPortNumber() { return 0; } /** * Returns a human-readable name for this Controller. */ public final String getName() { return name; } /** * Returns a non-localized string description of this controller. */ public String toString() { return name; } /** Returns the type of the Controller. */ public Type getType() { return Type.UNKNOWN; } /** * Creates a new EventQueue. Events in old queue are lost. */ public final void setEventQueueSize(int size) { try { setDeviceEventQueueSize(size); event_queue = new EventQueue(size); } catch (IOException e) { ControllerEnvironment.logln("Failed to create new event queue of size " + size + ": " + e); } } /** * Plugins override this method to adjust their internal event queue size */ protected void setDeviceEventQueueSize(int size) throws IOException { } public final EventQueue getEventQueue() { return event_queue; } protected abstract boolean getNextDeviceEvent(Event event) throws IOException; protected void pollDevice() throws IOException { } /* poll() is synchronized to protect the static event */ public synchronized boolean poll() { Component[] components = getComponents(); try { pollDevice(); for (int i = 0; i < components.length; i++) { AbstractComponent component = (AbstractComponent)components[i]; if (component.isRelative()) { component.setPollData(0); } else { // Let the component poll itself lazily component.resetHasPolled(); } } while (getNextDeviceEvent(event)) { AbstractComponent component = (AbstractComponent)event.getComponent(); float value = event.getValue(); if (component.isRelative()) { if (value == 0) continue; component.setPollData(component.getPollData() + value); } else { if (value == component.getEventValue()) continue; component.setEventValue(value); } if (!event_queue.isFull()) event_queue.add(event); } return true; } catch (IOException e) { ControllerEnvironment.logln("Failed to poll device: " + e.getMessage()); return false; } } } // class AbstractController jinput-20100502/coreAPI/src/java/net/java/games/input/ControllerEvent.java0000644000175000017500000000475707670200706026161 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * An event that is fired when the state of a controller changes */ public class ControllerEvent { private Controller controller; /** * Creates a controller event object. */ public ControllerEvent(Controller c) { controller = c; } /** * Returns the controller for this event. */ public Controller getController() { return controller; } } // class ControllerEvent jinput-20100502/coreAPI/src/java/net/java/games/input/Event.java0000644000175000017500000000555610424764250024113 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; public final class Event { private Component component; private float value; private long nanos; public final void set(Event other) { this.set(other.getComponent(), other.getValue(), other.getNanos()); } public final void set(Component component, float value, long nanos) { this.component = component; this.value = value; this.nanos = nanos; } public final Component getComponent() { return component; } public final float getValue() { return value; } /** * Return the time the event happened, in nanoseconds. * The time is relative and therefore can only be used * to compare with other event times. */ public final long getNanos() { return nanos; } public final String toString() { return "Event: component = " + component + " | value = " + value; } } jinput-20100502/coreAPI/src/java/net/java/games/input/Controller.java0000644000175000017500000002041510641024621025134 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * A Controller represents a physical device, such as a keyboard, mouse, * or joystick, or a logical grouping of related controls, such as a button * pad or mouse ball. A controller can be composed of multiple controllers. * For example, the ball of a mouse and its buttons are two separate * controllers. */ public interface Controller { /** * Returns the controllers connected to make up this controller, or * an empty array if this controller contains no child controllers. * The objects in the array are returned in order of assignment priority * (primary stick, secondary buttons, etc.). */ public abstract Controller[] getControllers(); /** * Returns the type of the Controller. */ public abstract Type getType(); /** * Returns the components on this controller, in order of assignment priority. * For example, the button controller on a mouse returns an array containing * the primary or leftmost mouse button, followed by the secondary or * rightmost mouse button (if present), followed by the middle mouse button * (if present). * The array returned is an empty array if this controller contains no components * (such as a logical grouping of child controllers). */ public abstract Component[] getComponents(); /** * Returns a single axis based on its type, or null * if no axis with the specified type could be found. */ public abstract Component getComponent(Component.Identifier id); /** * Returns the rumblers for sending feedback to this controller, or an * empty array if there are no rumblers on this controller. */ public abstract Rumbler[] getRumblers(); /** * Polls axes for data. Returns false if the controller is no longer valid. * Polling reflects the current state of the device when polled. */ public abstract boolean poll(); /** * Initialized the controller event queue to a new size. Existing events * in the queue are lost. */ public abstract void setEventQueueSize(int size); /** * Get the device event queue */ public abstract EventQueue getEventQueue(); /** * Returns the port type for this Controller. */ public abstract PortType getPortType(); /** * Returns the zero-based port number for this Controller. */ public abstract int getPortNumber(); /** * Returns a human-readable name for this Controller. */ public abstract String getName(); /** * Types of controller objects. */ public static class Type { /** * Name of controller type */ private final String name; /** * Protected constructor */ protected Type(String name) { this.name = name; } /** * Returns a non-localized string description of this controller type. */ public String toString() { return name; } /** * Unkown controller type. */ public static final Type UNKNOWN = new Type("Unknown"); /** * Mouse controller. */ public static final Type MOUSE = new Type("Mouse"); /** * A keyboard controller */ public static final Type KEYBOARD = new Type("Keyboard"); /** * Fingerstick controller; note that this may be sometimes treated as a * type of mouse or stick. */ public static final Type FINGERSTICK = new Type("Fingerstick"); /** * Gamepad controller. */ public static final Type GAMEPAD = new Type("Gamepad"); /** * Headtracker controller. */ public static final Type HEADTRACKER = new Type("Headtracker"); /** * Rudder controller. */ public static final Type RUDDER = new Type("Rudder"); /** * Stick controller, such as a joystick or flightstick. */ public static final Type STICK = new Type("Stick"); /** * A trackball controller; note that this may sometimes be treated as a * type of mouse. */ public static final Type TRACKBALL = new Type("Trackball"); /** * A trackpad, such as a tablet, touchpad, or glidepad; * note that this may sometimes be treated as a type of mouse. */ public static final Type TRACKPAD = new Type("Trackpad"); /** * A wheel controller, such as a steering wheel (note * that a mouse wheel is considered part of a mouse, not a * wheel controller). */ public static final Type WHEEL = new Type("Wheel"); } // class Controller.Type /** * Common controller port types. */ public static final class PortType { /** * Name of port type */ private final String name; /** * Protected constructor */ protected PortType(String name) { this.name = name; } /** * Returns a non-localized string description of this port type. */ public String toString() { return name; } /** * Unknown port type */ public static final PortType UNKNOWN = new PortType("Unknown"); /** * USB port */ public static final PortType USB = new PortType("USB port"); /** * Standard game port */ public static final PortType GAME = new PortType("Game port"); /** * Network port */ public static final PortType NETWORK = new PortType("Network port"); /** * Serial port */ public static final PortType SERIAL = new PortType("Serial port"); /** * i8042 */ public static final PortType I8042 = new PortType("i8042 (PS/2)"); /** * Parallel port */ public static final PortType PARALLEL = new PortType("Parallel port"); } // class Controller.PortType } // interface Controller jinput-20100502/coreAPI/src/java/net/java/games/input/Component.java0000644000175000017500000010216310435322672024764 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * An axis is a single button, slider, or dial, which has a single range. An * axis can hold information for motion (linear or rotational), velocity, * force, or acceleration. */ public interface Component { /** * Returns the identifier of the axis. */ public abstract Identifier getIdentifier(); /** * Returns true if data returned from poll * is relative to the last call, or false if data * is absolute. */ public abstract boolean isRelative(); /** * Returns whether or not the axis is analog, or false if it is digital. */ public abstract boolean isAnalog(); /** * Returns the suggested dead zone for this axis. Dead zone is the * amount polled data can vary before considered a significant change * in value. An application can safely ignore changes less than this * value in the positive or negative direction. * @see #getPollData */ public abstract float getDeadZone(); /** * Returns the data from the last time the control has been polled. * If this axis is a button, the value returned will be either 0.0f or 1.0f. * If this axis is normalized, the value returned will be between -1.0f and * 1.0f. * @see Controller#poll */ public abstract float getPollData(); /** * Returns a human-readable name for this axis. */ public abstract String getName(); /** * Identifiers for different Axes. */ public static class Identifier { /** * Name of axis type */ private final String name; /** * Protected constructor */ protected Identifier(String name) { this.name = name; } /** * Returns a non-localized string description of this axis type. */ public String getName() { return name; } /** * Returns a non-localized string description of this axis type. */ public String toString() { return name; } public static class Axis extends Identifier { /** * @param name */ protected Axis(String name) { super(name); } /** * An axis for specifying vertical data. */ public static final Axis X = new Axis("x"); /** * An axis for specifying horizontal data. */ public static final Axis Y = new Axis("y"); /** * An axis for specifying third dimensional up/down * data, or linear data in any direction that is * neither horizontal nor vertical. */ public static final Axis Z = new Axis("z"); /** * An axis for specifying left-right rotational data. */ public static final Axis RX = new Axis("rx"); /** * An axis for specifying forward-back rotational data. */ public static final Axis RY = new Axis("ry"); /** * An axis for specifying up-down rotational data * (rudder control). */ public static final Axis RZ = new Axis("rz"); /** * An axis for a slider or mouse wheel. */ public static final Axis SLIDER = new Axis("slider"); /** * An axis for slider or mouse wheel acceleration data. */ public static final Axis SLIDER_ACCELERATION = new Axis("slider-acceleration"); /** * An axis for slider force data. */ public static final Axis SLIDER_FORCE = new Axis("slider-force"); /** * An axis for slider or mouse wheel velocity data. */ public static final Axis SLIDER_VELOCITY = new Axis("slider-velocity"); /** * An axis for specifying vertical acceleration data. */ public static final Axis X_ACCELERATION = new Axis("x-acceleration"); /** * An axis for specifying vertical force data. */ public static final Axis X_FORCE = new Axis("x-force"); /** * An axis for specifying vertical velocity data. */ public static final Axis X_VELOCITY = new Axis("x-velocity"); /** * An axis for specifying horizontal acceleration data. */ public static final Axis Y_ACCELERATION = new Axis("y-acceleration"); /** * An axis for specifying horizontal force data. */ public static final Axis Y_FORCE = new Axis("y-force"); /** * An axis for specifying horizontal velocity data. */ public static final Axis Y_VELOCITY = new Axis("y-velocity"); /** * An axis for specifying third dimensional up/down acceleration data. */ public static final Axis Z_ACCELERATION = new Axis("z-acceleration"); /** * An axis for specifying third dimensional up/down force data. */ public static final Axis Z_FORCE = new Axis("z-force"); /** * An axis for specifying third dimensional up/down velocity data. */ public static final Axis Z_VELOCITY = new Axis("z-velocity"); /** * An axis for specifying left-right angular acceleration data. */ public static final Axis RX_ACCELERATION = new Axis("rx-acceleration"); /** * An axis for specifying left-right angular force (torque) data. */ public static final Axis RX_FORCE = new Axis("rx-force"); /** * An axis for specifying left-right angular velocity data. */ public static final Axis RX_VELOCITY = new Axis("rx-velocity"); /** * An axis for specifying forward-back angular acceleration data. */ public static final Axis RY_ACCELERATION = new Axis("ry-acceleration"); /** * An axis for specifying forward-back angular force (torque) data. */ public static final Axis RY_FORCE = new Axis("ry-force"); /** * An axis for specifying forward-back angular velocity data. */ public static final Axis RY_VELOCITY = new Axis("ry-velocity"); /** * An axis for specifying up-down angular acceleration data. */ public static final Axis RZ_ACCELERATION = new Axis("rz-acceleration"); /** * An axis for specifying up-down angular force (torque) data. */ public static final Axis RZ_FORCE = new Axis("rz-force"); /** * An axis for specifying up-down angular velocity data. */ public static final Axis RZ_VELOCITY = new Axis("rz-velocity"); /** * An axis for a point-of-view control. */ public static final Axis POV = new Axis("pov"); /** * An unknown axis. */ public static final Axis UNKNOWN = new Axis("unknown"); } public static class Button extends Identifier { public Button(String name) { super(name); } /** First device button */ public static final Button _0 = new Button("0"); /** Second device button */ public static final Button _1 = new Button("1"); /** Thrid device button */ public static final Button _2 = new Button("2"); /** Fourth device button */ public static final Button _3 = new Button("3"); /** Fifth device button */ public static final Button _4 = new Button("4"); /** Sixth device button */ public static final Button _5 = new Button("5"); /** Seventh device button */ public static final Button _6 = new Button("6"); /** Eighth device button */ public static final Button _7 = new Button("7"); /** Ninth device button */ public static final Button _8 = new Button("8"); /** 10th device button */ public static final Button _9 = new Button("9"); public static final Button _10 = new Button("10"); public static final Button _11 = new Button("11"); public static final Button _12 = new Button("12"); public static final Button _13 = new Button("13"); public static final Button _14 = new Button("14"); public static final Button _15 = new Button("15"); public static final Button _16 = new Button("16"); public static final Button _17 = new Button("17"); public static final Button _18 = new Button("18"); public static final Button _19 = new Button("19"); public static final Button _20 = new Button("20"); public static final Button _21 = new Button("21"); public static final Button _22 = new Button("22"); public static final Button _23 = new Button("23"); public static final Button _24 = new Button("24"); public static final Button _25 = new Button("25"); public static final Button _26 = new Button("26"); public static final Button _27 = new Button("27"); public static final Button _28 = new Button("28"); public static final Button _29 = new Button("29"); public static final Button _30 = new Button("30"); public static final Button _31 = new Button("31"); /** Joystick trigger button */ public static final Button TRIGGER = new Button("Trigger"); /** Joystick thumb button */ public static final Button THUMB = new Button("Thumb"); /** Second joystick thumb button */ public static final Button THUMB2 = new Button("Thumb 2"); /** Joystick top button */ public static final Button TOP = new Button("Top"); /** Second joystick top button */ public static final Button TOP2 = new Button("Top 2"); /** The joystick button you play with with you little finger (Pinkie on *that* side * of the pond :P) */ public static final Button PINKIE = new Button("Pinkie"); /** Joystick button on the base of the device */ public static final Button BASE = new Button("Base"); /** Second joystick button on the base of the device */ public static final Button BASE2 = new Button("Base 2"); /** Thrid joystick button on the base of the device */ public static final Button BASE3 = new Button("Base 3"); /** Fourth joystick button on the base of the device */ public static final Button BASE4 = new Button("Base 4"); /** Fifth joystick button on the base of the device */ public static final Button BASE5 = new Button("Base 5"); /** Sixth joystick button on the base of the device */ public static final Button BASE6 = new Button("Base 6"); /** erm, dunno, but it's in the defines so it might exist. */ public static final Button DEAD = new Button("Dead"); /** 'A' button on a gamepad */ public static final Button A = new Button("A"); /** 'B' button on a gamepad */ public static final Button B = new Button("B"); /** 'C' button on a gamepad */ public static final Button C = new Button("C"); /** 'X' button on a gamepad */ public static final Button X = new Button("X"); /** 'Y' button on a gamepad */ public static final Button Y = new Button("Y"); /** 'Z' button on a gamepad */ public static final Button Z = new Button("Z"); /** Left thumb button on a gamepad */ public static final Button LEFT_THUMB = new Button("Left Thumb"); /** Right thumb button on a gamepad */ public static final Button RIGHT_THUMB = new Button("Right Thumb"); /** Second left thumb button on a gamepad */ public static final Button LEFT_THUMB2 = new Button("Left Thumb 2"); /** Second right thumb button on a gamepad */ public static final Button RIGHT_THUMB2 = new Button("Right Thumb 2"); /** 'Select' button on a gamepad */ public static final Button SELECT = new Button("Select"); /** 'Mode' button on a gamepad */ public static final Button MODE = new Button("Mode"); /** Another left thumb button on a gamepad (how many thumbs do you have??) */ public static final Button LEFT_THUMB3 = new Button("Left Thumb 3"); /** Another right thumb button on a gamepad */ public static final Button RIGHT_THUMB3 = new Button("Right Thumb 3"); /** Digitiser pen tool button */ public static final Button TOOL_PEN = new Button("Pen"); /** Digitiser rubber (eraser) tool button */ public static final Button TOOL_RUBBER = new Button("Rubber"); /** Digitiser brush tool button */ public static final Button TOOL_BRUSH = new Button("Brush"); /** Digitiser pencil tool button */ public static final Button TOOL_PENCIL = new Button("Pencil"); /** Digitiser airbrush tool button */ public static final Button TOOL_AIRBRUSH = new Button("Airbrush"); /** Digitiser finger tool button */ public static final Button TOOL_FINGER = new Button("Finger"); /** Digitiser mouse tool button */ public static final Button TOOL_MOUSE = new Button("Mouse"); /** Digitiser lens tool button */ public static final Button TOOL_LENS = new Button("Lens"); /** Digitiser touch button */ public static final Button TOUCH = new Button("Touch"); /** Digitiser stylus button */ public static final Button STYLUS = new Button("Stylus"); /** Second digitiser stylus button */ public static final Button STYLUS2 = new Button("Stylus 2"); /** * An unknown button */ public static final Button UNKNOWN = new Button("Unknown"); /** * Returns the back mouse button. */ public static final Button BACK = new Button("Back"); /** * Returns the extra mouse button. */ public static final Button EXTRA = new Button("Extra"); /** * Returns the forward mouse button. */ public static final Button FORWARD = new Button("Forward"); /** * The primary or leftmost mouse button. */ public static final Button LEFT = new Button("Left"); /** * Returns the middle mouse button, not present if the mouse has fewer than three buttons. */ public static final Button MIDDLE = new Button("Middle"); /** * The secondary or rightmost mouse button, not present if the mouse is a single-button mouse. */ public static final Button RIGHT = new Button("Right"); /** * Returns the side mouse button. */ public static final Button SIDE = new Button("Side"); } /** * KeyIDs for standard PC (LATIN-1) keyboards */ public static class Key extends Identifier { /** * Protected constructor */ protected Key(String name) { super(name); } /** * Standard keyboard (LATIN-1) keys * UNIX X11 keysym values are listed to the right */ public static final Key VOID = new Key("Void"); // MS 0x00 UNIX 0xFFFFFF public static final Key ESCAPE = new Key("Escape"); // MS 0x01 UNIX 0xFF1B public static final Key _1 = new Key("1"); // MS 0x02 UNIX 0x031 EXCLAM 0x021 public static final Key _2 = new Key("2"); // MS 0x03 UNIX 0x032 AT 0x040 public static final Key _3 = new Key("3"); // MS 0x04 UNIX 0x033 NUMBERSIGN 0x023 public static final Key _4 = new Key("4"); // MS 0x05 UNIX 0x034 DOLLAR 0x024 public static final Key _5 = new Key("5"); // MS 0x06 UNIX 0x035 PERCENT 0x025 public static final Key _6 = new Key("6"); // MS 0x07 UNIX 0x036 CIRCUMFLEX 0x05e public static final Key _7 = new Key("7"); // MS 0x08 UNIX 0x037 AMPERSAND 0x026 public static final Key _8 = new Key("8"); // MS 0x09 UNIX 0x038 ASTERISK 0x02a public static final Key _9 = new Key("9"); // MS 0x0A UNIX 0x039 PARENLEFT 0x028 public static final Key _0 = new Key("0"); // MS 0x0B UNIX 0x030 PARENRIGHT 0x029 public static final Key MINUS = new Key("-"); // MS 0x0C UNIX 0x02d UNDERSCORE 0x05f public static final Key EQUALS = new Key("="); // MS 0x0D UNIX 0x03d PLUS 0x02b public static final Key BACK = new Key("Back"); // MS 0x0E UNIX 0xFF08 public static final Key TAB = new Key("Tab"); // MS 0x0F UNIX 0xFF09 public static final Key Q = new Key("Q"); // MS 0x10 UNIX 0x071 UPPER 0x051 public static final Key W = new Key("W"); // MS 0x11 UNIX 0x077 UPPER 0x057 public static final Key E = new Key("E"); // MS 0x12 UNIX 0x065 UPPER 0x045 public static final Key R = new Key("R"); // MS 0x13 UNIX 0x072 UPPER 0x052 public static final Key T = new Key("T"); // MS 0x14 UNIX 0x074 UPPER 0x054 public static final Key Y = new Key("Y"); // MS 0x15 UNIX 0x079 UPPER 0x059 public static final Key U = new Key("U"); // MS 0x16 UNIX 0x075 UPPER 0x055 public static final Key I = new Key("I"); // MS 0x17 UNIX 0x069 UPPER 0x049 public static final Key O = new Key("O"); // MS 0x18 UNIX 0x06F UPPER 0x04F public static final Key P = new Key("P"); // MS 0x19 UNIX 0x070 UPPER 0x050 public static final Key LBRACKET = new Key("["); // MS 0x1A UNIX 0x05b BRACE 0x07b public static final Key RBRACKET = new Key("]"); // MS 0x1B UNIX 0x05d BRACE 0x07d public static final Key RETURN = new Key("Return"); // MS 0x1C UNIX 0xFF0D public static final Key LCONTROL = new Key("Left Control"); // MS 0x1D UNIX 0xFFE3 public static final Key A = new Key("A"); // MS 0x1E UNIX 0x061 UPPER 0x041 public static final Key S = new Key("S"); // MS 0x1F UNIX 0x073 UPPER 0x053 public static final Key D = new Key("D"); // MS 0x20 UNIX 0x064 UPPER 0x044 public static final Key F = new Key("F"); // MS 0x21 UNIX 0x066 UPPER 0x046 public static final Key G = new Key("G"); // MS 0x22 UNIX 0x067 UPPER 0x047 public static final Key H = new Key("H"); // MS 0x23 UNIX 0x068 UPPER 0x048 public static final Key J = new Key("J"); // MS 0x24 UNIX 0x06A UPPER 0x04A public static final Key K = new Key("K"); // MS 0x25 UNIX 0x06B UPPER 0x04B public static final Key L = new Key("L"); // MS 0x26 UNIX 0x06C UPPER 0x04C public static final Key SEMICOLON = new Key(";"); // MS 0x27 UNIX 0x03b COLON 0x03a public static final Key APOSTROPHE = new Key("'"); // MS 0x28 UNIX 0x027 QUOTEDBL 0x022 public static final Key GRAVE = new Key("~"); // MS 0x29 UNIX 0x060 TILDE 0x07e public static final Key LSHIFT = new Key("Left Shift"); // MS 0x2A UNIX 0xFFE1 public static final Key BACKSLASH = new Key("\\"); // MS 0x2B UNIX 0x05c BAR 0x07c public static final Key Z = new Key("Z"); // MS 0x2C UNIX 0x07A UPPER 0x05A public static final Key X = new Key("X"); // MS 0x2D UNIX 0x078 UPPER 0x058 public static final Key C = new Key("C"); // MS 0x2E UNIX 0x063 UPPER 0x043 public static final Key V = new Key("V"); // MS 0x2F UNIX 0x076 UPPER 0x056 public static final Key B = new Key("B"); // MS 0x30 UNIX 0x062 UPPER 0x042 public static final Key N = new Key("N"); // MS 0x31 UNIX 0x06E UPPER 0x04E public static final Key M = new Key("M"); // MS 0x32 UNIX 0x06D UPPER 0x04D public static final Key COMMA = new Key(","); // MS 0x33 UNIX 0x02c LESS 0x03c public static final Key PERIOD = new Key("."); // MS 0x34 UNIX 0x02e GREATER 0x03e public static final Key SLASH = new Key("/"); // MS 0x35 UNIX 0x02f QUESTION 0x03f public static final Key RSHIFT = new Key("Right Shift"); // MS 0x36 UNIX 0xFFE2 public static final Key MULTIPLY = new Key("Multiply"); // MS 0x37 UNIX 0xFFAA public static final Key LALT = new Key("Left Alt"); // MS 0x38 UNIX 0xFFE9 public static final Key SPACE = new Key(" "); // MS 0x39 UNIX 0x020 public static final Key CAPITAL = new Key("Caps Lock"); // MS 0x3A UNIX 0xFFE5 SHIFTLOCK 0xFFE6 public static final Key F1 = new Key("F1"); // MS 0x3B UNIX 0xFFBE public static final Key F2 = new Key("F2"); // MS 0x3C UNIX 0xFFBF public static final Key F3 = new Key("F3"); // MS 0x3D UNIX 0xFFC0 public static final Key F4 = new Key("F4"); // MS 0x3E UNIX 0xFFC1 public static final Key F5 = new Key("F5"); // MS 0x3F UNIX 0xFFC2 public static final Key F6 = new Key("F6"); // MS 0x40 UNIX 0xFFC3 public static final Key F7 = new Key("F7"); // MS 0x41 UNIX 0xFFC4 public static final Key F8 = new Key("F8"); // MS 0x42 UNIX 0xFFC5 public static final Key F9 = new Key("F9"); // MS 0x43 UNIX 0xFFC6 public static final Key F10 = new Key("F10"); // MS 0x44 UNIX 0xFFC7 public static final Key NUMLOCK = new Key("Num Lock"); // MS 0x45 UNIX 0xFF7F public static final Key SCROLL = new Key("Scroll Lock"); // MS 0x46 UNIX 0xFF14 public static final Key NUMPAD7 = new Key("Num 7"); // MS 0x47 UNIX 0xFFB7 HOME 0xFF95 public static final Key NUMPAD8 = new Key("Num 8"); // MS 0x48 UNIX 0xFFB8 UP 0xFF97 public static final Key NUMPAD9 = new Key("Num 9"); // MS 0x49 UNIX 0xFFB9 PRIOR 0xFF9A public static final Key SUBTRACT = new Key("Num -"); // MS 0x4A UNIX 0xFFAD public static final Key NUMPAD4 = new Key("Num 4"); // MS 0x4B UNIX 0xFFB4 LEFT 0xFF96 public static final Key NUMPAD5 = new Key("Num 5"); // MS 0x4C UNIX 0xFFB5 public static final Key NUMPAD6 = new Key("Num 6"); // MS 0x4D UNIX 0xFFB6 RIGHT 0xFF98 public static final Key ADD = new Key("Num +"); // MS 0x4E UNIX 0xFFAB public static final Key NUMPAD1 = new Key("Num 1"); // MS 0x4F UNIX 0xFFB1 END 0xFF9C public static final Key NUMPAD2 = new Key("Num 2"); // MS 0x50 UNIX 0xFFB2 DOWN 0xFF99 public static final Key NUMPAD3 = new Key("Num 3"); // MS 0x51 UNIX 0xFFB3 NEXT 0xFF9B public static final Key NUMPAD0 = new Key("Num 0"); // MS 0x52 UNIX 0xFFB0 INSERT 0xFF9E public static final Key DECIMAL = new Key("Num ."); // MS 0x53 UNIX 0xFFAE DELETE 0xFF9F public static final Key F11 = new Key("F11"); // MS 0x57 UNIX 0xFFC8 public static final Key F12 = new Key("F12"); // MS 0x58 UNIX 0xFFC9 public static final Key F13 = new Key("F13"); // MS 0x64 UNIX 0xFFCA public static final Key F14 = new Key("F14"); // MS 0x65 UNIX 0xFFCB public static final Key F15 = new Key("F15"); // MS 0x66 UNIX 0xFFCC public static final Key KANA = new Key("Kana"); // MS 0x70 UNIX 0xFF2D public static final Key CONVERT = new Key("Convert"); // MS 0x79 Japanese keyboard public static final Key NOCONVERT = new Key("Noconvert"); // MS 0x7B Japanese keyboard public static final Key YEN = new Key("Yen"); // MS 0x7D UNIX 0x0a5 public static final Key NUMPADEQUAL = new Key("Num ="); // MS 0x8D UNIX 0xFFBD public static final Key CIRCUMFLEX = new Key("Circumflex"); // MS 0x90 Japanese keyboard public static final Key AT = new Key("At"); // MS 0x91 UNIX 0x040 public static final Key COLON = new Key("Colon"); // MS 0x92 UNIX 0x03a public static final Key UNDERLINE = new Key("Underline"); // MS 0x93 NEC PC98 public static final Key KANJI = new Key("Kanji"); // MS 0x94 UNIX 0xFF21 public static final Key STOP = new Key("Stop"); // MS 0x95 UNIX 0xFF69 public static final Key AX = new Key("Ax"); // MS 0x96 Japan AX public static final Key UNLABELED = new Key("Unlabeled"); // MS 0x97 J3100 public static final Key NUMPADENTER = new Key("Num Enter"); // MS 0x9C UNIX 0xFF8D public static final Key RCONTROL = new Key("Right Control"); // MS 0x9D UNIX 0xFFE4 public static final Key NUMPADCOMMA = new Key("Num ,"); // MS 0xB3 UNIX 0xFFAC public static final Key DIVIDE = new Key("Num /"); // MS 0xB5 UNIX 0xFFAF public static final Key SYSRQ = new Key("SysRq"); // MS 0xB7 UNIX 0xFF15 PRINT 0xFF61 public static final Key RALT = new Key("Right Alt"); // MS 0xB8 UNIX 0xFFEA public static final Key PAUSE = new Key("Pause"); // MS 0xC5 UNIX 0xFF13 BREAK 0xFF6B public static final Key HOME = new Key("Home"); // MS 0xC7 UNIX 0xFF50 public static final Key UP = new Key("Up"); // MS 0xC8 UNIX 0xFF52 public static final Key PAGEUP = new Key("Pg Up"); // MS 0xC9 UNIX 0xFF55 public static final Key LEFT = new Key("Left"); // MS 0xCB UNIX 0xFF51 public static final Key RIGHT = new Key("Right"); // MS 0xCD UNIX 0xFF53 public static final Key END = new Key("End"); // MS 0xCF UNIX 0xFF57 public static final Key DOWN = new Key("Down"); // MS 0xD0 UNIX 0xFF54 public static final Key PAGEDOWN = new Key("Pg Down"); // MS 0xD1 UNIX 0xFF56 public static final Key INSERT = new Key("Insert"); // MS 0xD2 UNIX 0xFF63 public static final Key DELETE = new Key("Delete"); // MS 0xD3 UNIX 0xFFFF public static final Key LWIN = new Key("Left Windows"); // MS 0xDB UNIX META 0xFFE7 SUPER 0xFFEB HYPER 0xFFED public static final Key RWIN = new Key("Right Windows"); // MS 0xDC UNIX META 0xFFE8 SUPER 0xFFEC HYPER 0xFFEE public static final Key APPS = new Key("Apps"); // MS 0xDD UNIX 0xFF67 public static final Key POWER = new Key("Power"); // MS 0xDE Sun 0x1005FF76 SHIFT 0x1005FF7D public static final Key SLEEP = new Key("Sleep"); // MS 0xDF No UNIX keysym public static final Key UNKNOWN = new Key("Unknown"); } // class StandardKeyboard.KeyID } // class Axis.Identifier /** * POV enum for different positions. */ public static class POV { /** * Standard value for center HAT position */ public static final float OFF = 0.0f; /** * Synonmous with OFF */ public static final float CENTER = OFF; /** * Standard value for up-left HAT position */ public static final float UP_LEFT = 0.125f; /** * Standard value for up HAT position */ public static final float UP = 0.25f; /** * Standard value for up-right HAT position */ public static final float UP_RIGHT = 0.375f; /** * Standard value for right HAT position */ public static final float RIGHT = 0.50f; /** * Standard value for down-right HAT position */ public static final float DOWN_RIGHT = 0.625f; /** * Standard value for down HAT position */ public static final float DOWN = 0.75f; /** * Standard value for down-left HAT position */ public static final float DOWN_LEFT = 0.875f; /** * Standard value for left HAT position */ public static final float LEFT = 1.0f; } // class Axis.POV } // interface Axis jinput-20100502/coreAPI/src/java/net/java/games/input/ControllerEnvironment.java0000644000175000017500000001375311273015044027371 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.File; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Iterator; import java.util.logging.Logger; /** * A ControllerEnvironment represents a collection of controllers that are * physically or logically linked. By default, this corresponds to the * environment for the local machine. *

    * In this reference implementation, this class can also be used to register * controllers with the default environment as "plug-ins". A plug-in is * created by subclassing ControllerEnvironment with a class that has a public * no-argument constructor, implements the net.java.games.util.plugins.Plugin * interface and has a name ending in "Plugin". * (See net.java.games.input.DirectInputEnvironmentPlugin in the DXplugin * part of the source tree for an example.) * * When the DefaultControllerEnvrionment is instanced it uses the plugin library * to look for Plugins in both [java.home]/lib/controller and * [user.dir]/controller. This allows controller plugins to be installed either * globally for the entire Java environment or locally for just one particular * Java app. * * For more information on the organization of plugins within the controller * root directories, see net.java.games.util.plugins.Plugins (Note the * plural -- "Plugins" not "Plugin" which is just a marker interface.) * */ public abstract class ControllerEnvironment { static void logln(String msg) { log(msg + "\n"); } static void log(String msg) { Logger.getLogger(ControllerEnvironment.class.getName()).info(msg); } /** * The default controller environment */ private static ControllerEnvironment defaultEnvironment = new DefaultControllerEnvironment(); /** * List of controller listeners */ protected final ArrayList controllerListeners = new ArrayList(); /** * Protected constructor for subclassing. */ protected ControllerEnvironment() { } /** * Returns a list of all controllers available to this environment, * or an empty array if there are no controllers in this environment. */ public abstract Controller[] getControllers(); /** * Adds a listener for controller state change events. */ public void addControllerListener(ControllerListener l) { assert l != null; controllerListeners.add(l); } /** * Returns the isSupported status of this environment. * What makes an environment supported or not is up to the * particular plugin, but may include OS or available hardware. */ public abstract boolean isSupported(); /** * Removes a listener for controller state change events. */ public void removeControllerListener(ControllerListener l) { assert l != null; controllerListeners.remove(l); } /** * Creates and sends an event to the controller listeners that a controller * has been added. */ protected void fireControllerAdded(Controller c) { ControllerEvent ev = new ControllerEvent(c); Iterator it = controllerListeners.iterator(); while (it.hasNext()) { ((ControllerListener)it.next()).controllerAdded(ev); } } /** * Creates and sends an event to the controller listeners that a controller * has been lost. */ protected void fireControllerRemoved(Controller c) { ControllerEvent ev = new ControllerEvent(c); Iterator it = controllerListeners.iterator(); while (it.hasNext()) { ((ControllerListener)it.next()).controllerRemoved(ev); } } /** * Returns the default environment for input controllers. * This usually corresponds to the environment for the local machine. */ public static ControllerEnvironment getDefaultEnvironment() { return defaultEnvironment; } } // ControllerEnvironment jinput-20100502/coreAPI/build.xml0000644000175000017500000000445111310716215016320 0ustar twernertwerner jinput-20100502/CHANGES0000644000175000017500000001000110424764246014210 0ustar twernertwernerMajor: - Flattened Mouse so it isn't separated into child controllers (ball, buttons). - Removed useless component members from Mouse and Keyboard. For example, Mouse.getX() is now simply getComponent(Component.Identifier.Axis.X). - Removed StandardKeyboard. - Removed Mouse.Button and Keyboard.Key since they only complicated plugins - Added Keyboard.isKeyDown(Component.Identifier.Key) (with default false for non-existent keys). - Removed Component.isPolling() and Component.setPolling(). - Removed Component.isNormalized() since all plugins return normalized data for absolute axes anyway. - Windows XP: Added RawInputEnvironmentPlugin to enable multiple mice and keyboards. DirectInput will only report one system mouse and one system keyboard where all mice and keyboard input are combined (in fact, Windows was the OS with the most complicated and confusing APIs, apart from the fact that I had to code two separate plugins for it). The RawInputEnvironment is not enabled per default, since it seems to exclude mouse and keybaord input to DirectInput which will probably confuse unsuspecting applications. But at least there is now a method to access multiple keyboards and mice on windows xp. - DirectInput: Got rid of the nasty DataFormat special case handling. The DirectInput data format is now one large (java int) array which is a better match for the jinput abstraction than the builtin DirectInput data formats for mice, keyboards and joysticks. - Added event queue support. An Event contains a Component, a value and a relative timestamp in nanoseconds. - Basically rewrote all plugins from scratch, with focus on minimizing the amount of native code in general, and in particular for moving decisions from native to java, making the native code more general purpose and less likely to need changes. Additionally, all plugins support the new event queue interface. All plugins now have much better error handling (exceptions) and much tighter native code (no more global variables, helper functions declared static etc.). Additionally, all plugin internal java classes are package protected and final for added security. - Mac OS X: Added missing features and fixed broken Mouse. - Cleaned up build system and added option for a combined jinput.jar with all plugins as opposed to just the OS specific packages - JInput should now be thread safe. - Mac OS X intel mac support. The jinput-osx.jnilib library is for 10.4 or better (both ppc and i386), while libjinput-osx-legacy.jnilib is for 10.3 or earlier. Minor: - Removed keyId from Component.Identifier.Key - Made components, children and rumblers final in AbstractController - Added Identifier->Component Map to AbstractController to avoid Keyboard special code and to speed up the Component.getComponent() method in general. - Added exceptions to native code for accurate error messages (instead of the standard printf). I use the checked IOException exclusively, but since exceptions are not exposed to user code, that can easily be changed. - Added printfJava(env, format, ...) to native code to avoid printfs altogether Issues not fixed: - Linux plugin report buttons ids with semantic value (trigger button, thumb button etc.) while all other plugins use simple button indices (0, 1, 2, 3 etc.). This is a property of the underlying linux input API and will probably confuse some jinput programs. - The Plugin architecture seems somewhat complex and IMHO unnecessary. It involves custom Classloaders to separate the each Plugin's namespaces, but since you can't use custom Classloaders in restricted environments (web start, applets) the plugins have to have manually separate namespaces anyway. I'm inclined to remove it, but since it was there originally, there is probably some use case it covers I don't know about. TODO: - A utility for collecting events from multiple controller at once. An application then just needs to register all its devices to the utility and only call poll() and getEventQueue() in one place. Event will probably need to be extended with a getController() method. jinput-20100502/build.xml0000644000175000017500000002344211362115755015050 0ustar twernertwerner jinput-20100502/www/0000755000175000017500000000000011367367574014063 5ustar twernertwernerjinput-20100502/www/index.html0000644000175000017500000001435611327525143016051 0ustar twernertwerner

    Welcome to the Java Input API Project!
    Overview

    The JInput Project hosts an implementation of an API for game controller discovery and polled input. It is part of a suite of open-source technologies initiated by the Game Technology Group at Sun Microsystems with intention of making the development of high performance games in Java a reality.

    The API itself is pure Java and presents a platform-neutral completely portable model of controller discovery and polling. It can handle arbitrary controllers and returns both human and machine understandable descriptions of the inputs available.

    The implementation hosted here also includes plug-ins to allow the API to adapt to various specific platforms. These plug-ins often contain a native code portion to interface to the host system.

    Project Status

    The intial implementation of the Java Input API is available for download from CVS. This release contains a plug-in for Win32i, Linux, and OSX. Builds are available in the Documents and Files area.

    Getting Started

    This project has been built in the following environment:

    This project requires that the Java Utils library (jutil.jar) be built and placed in this project's lib directories. See the README for more detail. For the Java Utils library itself see jutils.dev.java.net

    If you wish to become involved in the JInput project, please stop by our forums and introduce yourself.

     

    Useful Links
    Getting started
    Latest distribution
    JInput forums
    Developer Agreement
     
    jinput-20100502/plugins/0000755000175000017500000000000011367367574014720 5ustar twernertwernerjinput-20100502/plugins/wintab/0000755000175000017500000000000011367367574016204 5ustar twernertwernerjinput-20100502/plugins/wintab/src/0000755000175000017500000000000011367367574016773 5ustar twernertwernerjinput-20100502/plugins/wintab/src/native/0000755000175000017500000000000011367367574020261 5ustar twernertwernerjinput-20100502/plugins/wintab/src/native/net_java_games_input_WinTabContext.c0000644000175000017500000001102210521733066027374 0ustar twernertwerner#include #include #include #include "net_java_games_input_WinTabContext.h" #include //#define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ROTATION | PK_ORIENTATION | PK_CURSOR ) #define PACKETDATA ( PK_TIME | PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_CURSOR ) #define PACKETMODE 0 #include #include #define MAX_PACKETS 20 JNIEXPORT jlong JNICALL Java_net_java_games_input_WinTabContext_nOpen(JNIEnv *env, jclass unused, jlong hWnd_long) { LOGCONTEXT context; HWND hWnd = (HWND)(INT_PTR)hWnd_long; HCTX hCtx = NULL; jclass booleanClass = (*env)->FindClass(env, "java/lang/Boolean"); jstring propertyName = (*env)->NewStringUTF(env, "jinput.wintab.detachcursor"); jmethodID getBooleanMethod = (*env)->GetStaticMethodID(env, booleanClass, "getBoolean", "(Ljava/lang/String;)Z"); jboolean detachCursor = (*env)->CallStaticBooleanMethod(env, booleanClass, getBooleanMethod, propertyName); WTInfo(WTI_DEFCONTEXT, 0, &context); wsprintf(context.lcName, "JInput Digitizing"); context.lcPktData = PACKETDATA; context.lcPktMode = PACKETMODE; context.lcMoveMask = PACKETDATA; context.lcBtnUpMask = context.lcBtnDnMask; if(!detachCursor) { context.lcOptions |= CXO_SYSTEM; } /* open the region */ hCtx = WTOpen(hWnd, &context, TRUE); return (jlong)(intptr_t)hCtx; } JNIEXPORT void JNICALL Java_net_java_games_input_WinTabContext_nClose(JNIEnv *env, jclass unused, jlong hCtx_long) { WTClose((HCTX)(INT_PTR)hCtx_long); } JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabContext_nGetNumberOfSupportedDevices(JNIEnv *env, jclass unused) { int numDevices; WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices); return numDevices; } JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabContext_nGetPackets(JNIEnv *env, jclass unused, jlong hCtx_long) { jobjectArray retval; int i=0; PACKET packets[MAX_PACKETS]; int numberRead = WTPacketsGet((HCTX)(INT_PTR)hCtx_long, MAX_PACKETS, packets); jclass winTabPacketClass = (*env)->FindClass(env, "net/java/games/input/WinTabPacket"); jfieldID packetTimeField = (*env)->GetFieldID(env, winTabPacketClass, "PK_TIME", "J"); jfieldID packetXAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_X", "I"); jfieldID packetYAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_Y", "I"); jfieldID packetZAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_Z", "I"); jfieldID packetButtonsField = (*env)->GetFieldID(env, winTabPacketClass, "PK_BUTTONS", "I"); jfieldID packetNPressureAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_NORMAL_PRESSURE", "I"); jfieldID packetTPressureAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_TANGENT_PRESSURE", "I"); jfieldID packetCursorField = (*env)->GetFieldID(env, winTabPacketClass, "PK_CURSOR", "I"); jfieldID packetOrientationAltAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_ALT", "I"); jfieldID packetOrientationAzAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_AZ", "I"); jfieldID packetOrientationTwistAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_TWIST", "I"); jobject prototypePacket = newJObject(env, "net/java/games/input/WinTabPacket", "()V"); retval = (*env)->NewObjectArray(env, numberRead, winTabPacketClass, NULL); for(i=0;iSetLongField(env, tempPacket, packetTimeField, packets[i].pkTime); (*env)->SetIntField(env, tempPacket, packetXAxisField, packets[i].pkX); (*env)->SetIntField(env, tempPacket, packetYAxisField, packets[i].pkY); (*env)->SetIntField(env, tempPacket, packetZAxisField, packets[i].pkZ); (*env)->SetIntField(env, tempPacket, packetButtonsField, packets[i].pkButtons); (*env)->SetIntField(env, tempPacket, packetNPressureAxisField, packets[i].pkNormalPressure); (*env)->SetIntField(env, tempPacket, packetTPressureAxisField, packets[i].pkTangentPressure); (*env)->SetIntField(env, tempPacket, packetCursorField, packets[i].pkCursor); (*env)->SetIntField(env, tempPacket, packetOrientationAltAxisField, packets[i].pkOrientation.orAzimuth); (*env)->SetIntField(env, tempPacket, packetOrientationAzAxisField, packets[i].pkOrientation.orAltitude); (*env)->SetIntField(env, tempPacket, packetOrientationTwistAxisField, packets[i].pkOrientation.orTwist); (*env)->SetObjectArrayElement(env, retval, i, tempPacket); } return retval; } jinput-20100502/plugins/wintab/src/native/net_java_games_input_WinTabDevice.c0000644000175000017500000000717310521147566027167 0ustar twernertwerner#include #include #include #include "net_java_games_input_WinTabDevice.h" #include "net_java_games_input_WinTabComponent.h" #include "util.h" #include #include #define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR ) #define PACKETMODE 0 #include JNIEXPORT jstring JNICALL Java_net_java_games_input_WinTabDevice_nGetName(JNIEnv *env, jclass unused, jint deviceIndex) { char name[50]; WTInfo(WTI_DEVICES + deviceIndex, DVC_NAME, name); return (*env)->NewStringUTF(env, name); } JNIEXPORT jintArray JNICALL Java_net_java_games_input_WinTabDevice_nGetAxisDetails(JNIEnv *env, jclass unused, jint deviceIndex, jint axisId) { UINT type; AXIS threeAxisArray[3]; AXIS axis; long threeAxisData[6]; long axisData[2]; int res; jintArray retVal = NULL; if(axisId==net_java_games_input_WinTabComponent_XAxis) type = DVC_X; else if(axisId==net_java_games_input_WinTabComponent_YAxis) type = DVC_Y; else if(axisId==net_java_games_input_WinTabComponent_ZAxis) type = DVC_Z; else if(axisId==net_java_games_input_WinTabComponent_NPressureAxis) type = DVC_NPRESSURE; else if(axisId==net_java_games_input_WinTabComponent_TPressureAxis) type = DVC_TPRESSURE; else if(axisId==net_java_games_input_WinTabComponent_OrientationAxis) type = DVC_ORIENTATION; else if(axisId==net_java_games_input_WinTabComponent_RotationAxis) type = DVC_ROTATION; if(axisId==net_java_games_input_WinTabComponent_RotationAxis || axisId==net_java_games_input_WinTabComponent_OrientationAxis) { res = WTInfo(WTI_DEVICES + deviceIndex, type, &threeAxisArray); if(res!=0) { threeAxisData[0] = threeAxisArray[0].axMin; threeAxisData[1] = threeAxisArray[0].axMax; threeAxisData[2] = threeAxisArray[1].axMin; threeAxisData[3] = threeAxisArray[1].axMax; threeAxisData[4] = threeAxisArray[2].axMin; threeAxisData[5] = threeAxisArray[2].axMax; retVal = (*env)->NewIntArray(env, 6); (*env)->SetIntArrayRegion(env, retVal, 0, 6, threeAxisData); } } else { res = WTInfo(WTI_DEVICES + deviceIndex, type, &axis); if(res!=0) { axisData[0] = axis.axMin; axisData[1] = axis.axMax; retVal = (*env)->NewIntArray(env, 2); (*env)->SetIntArrayRegion(env, retVal, 0, 2, axisData); } } if(retVal==NULL) { retVal = (*env)->NewIntArray(env, 0); } return retVal; } JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabDevice_nGetCursorNames(JNIEnv *env, jclass unused, jint deviceId) { int numberCursorTypes; int firstCursorType; char name[50]; int i; jclass stringClass = (*env)->FindClass(env, "java/lang/String"); jstring nameString; jobjectArray retval; WTInfo(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes); WTInfo(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType); retval = (*env)->NewObjectArray(env, numberCursorTypes, stringClass, NULL); for(i=0;iNewStringUTF(env, name); (*env)->SetObjectArrayElement(env, retval, i-firstCursorType, nameString); } return retval; } JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabDevice_nGetMaxButtonCount(JNIEnv *env, jclass unused, jint deviceId) { int numberCursorTypes; int firstCursorType; byte buttonCount; int i; byte retval=0; WTInfo(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes); WTInfo(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType); for(i=0;iretval) { retval = buttonCount; } } return (jint)retval; } jinput-20100502/plugins/wintab/src/native/build.xml0000644000175000017500000000502410521164467022066 0ustar twernertwerner jinput-20100502/plugins/wintab/src/java/0000755000175000017500000000000011367367574017714 5ustar twernertwernerjinput-20100502/plugins/wintab/src/java/net/0000755000175000017500000000000011367367574020502 5ustar twernertwernerjinput-20100502/plugins/wintab/src/java/net/java/0000755000175000017500000000000011367367574021423 5ustar twernertwernerjinput-20100502/plugins/wintab/src/java/net/java/games/0000755000175000017500000000000011367367574022517 5ustar twernertwernerjinput-20100502/plugins/wintab/src/java/net/java/games/input/0000755000175000017500000000000011367367574023656 5ustar twernertwernerjinput-20100502/plugins/wintab/src/java/net/java/games/input/WinTabCursorComponent.java0000644000175000017500000000423210654437362030756 0ustar twernertwerner/** * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; public class WinTabCursorComponent extends WinTabComponent { private int index; protected WinTabCursorComponent(WinTabContext context, int parentDevice, String name, Identifier id, int index) { super(context, parentDevice, name, id); this.index = index; } public Event processPacket(WinTabPacket packet) { Event newEvent = null; if(packet.PK_CURSOR==index && lastKnownValue==0) { lastKnownValue = 1; newEvent = new Event(); newEvent.set(this, lastKnownValue, packet.PK_TIME*1000); } else if(packet.PK_CURSOR!=index && lastKnownValue==1) { lastKnownValue = 0; newEvent = new Event(); newEvent.set(this, lastKnownValue, packet.PK_TIME*1000); } return newEvent; } } jinput-20100502/plugins/wintab/src/java/net/java/games/input/WinTabComponent.java0000644000175000017500000001617110654437362027565 0ustar twernertwerner/** * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class WinTabComponent extends AbstractComponent { public final static int XAxis = 1; public final static int YAxis = 2; public final static int ZAxis = 3; public final static int NPressureAxis = 4; public final static int TPressureAxis = 5; public final static int OrientationAxis = 6; public final static int RotationAxis = 7; private int min; private int max; protected float lastKnownValue; private boolean analog; protected WinTabComponent(WinTabContext context, int parentDevice, String name, Identifier id, int min, int max) { super(name, id); this.min = min; this.max = max; analog = true; } protected WinTabComponent(WinTabContext context, int parentDevice, String name, Identifier id) { super(name, id); this.min = 0; this.max = 1; analog = false; } protected float poll() throws IOException { return lastKnownValue; } public boolean isAnalog() { return analog; } public boolean isRelative() { // All axis are absolute return false; } public static List createComponents(WinTabContext context, int parentDevice, int axisId, int[] axisRanges) { List components = new ArrayList(); Identifier id; switch(axisId) { case XAxis: id = Identifier.Axis.X; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1])); break; case YAxis: id = Identifier.Axis.Y; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1])); break; case ZAxis: id = Identifier.Axis.Z; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1])); break; case NPressureAxis: id = Identifier.Axis.X_FORCE; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1])); break; case TPressureAxis: id = Identifier.Axis.Y_FORCE; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1])); break; case OrientationAxis: id = Identifier.Axis.RX; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1])); id = Identifier.Axis.RY; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[2], axisRanges[3])); id = Identifier.Axis.RZ; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[4], axisRanges[5])); break; case RotationAxis: id = Identifier.Axis.RX; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[0], axisRanges[1])); id = Identifier.Axis.RY; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[2], axisRanges[3])); id = Identifier.Axis.RZ; components.add(new WinTabComponent(context, parentDevice, id.getName(), id, axisRanges[4], axisRanges[5])); break; } return components; } public static Collection createButtons(WinTabContext context, int deviceIndex, int numberOfButtons) { List buttons = new ArrayList(); Identifier id; for(int i=0;i0) ? 1.0f : 0.0f; if(newValue!=getPollData()) { lastKnownValue = newValue; //Generate an event newEvent = new Event(); newEvent.set(this, newValue, packet.PK_TIME*1000); return newEvent; } return newEvent; } } jinput-20100502/plugins/wintab/src/java/net/java/games/input/WinTabDevice.java0000644000175000017500000001506610654437362027024 0ustar twernertwerner/** * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class WinTabDevice extends AbstractController { private WinTabContext context; private List eventList = new ArrayList(); private WinTabDevice(WinTabContext context, int index, String name, Component[] components) { super(name, components, new Controller[0], new Rumbler[0]); this.context = context; } protected boolean getNextDeviceEvent(Event event) throws IOException { if(eventList.size()>0) { Event ourEvent = (Event)eventList.remove(0); event.set(ourEvent); return true; } else { return false; } } protected void pollDevice() throws IOException { // Get the data off the native queue. context.processEvents(); super.pollDevice(); } public Type getType() { return Type.TRACKPAD; } public void processPacket(WinTabPacket packet) { Component[] components = getComponents(); for(int i=0;i jinput-20100502/plugins/common/0000755000175000017500000000000011367367570016204 5ustar twernertwernerjinput-20100502/plugins/common/src/0000755000175000017500000000000011367367570016773 5ustar twernertwernerjinput-20100502/plugins/common/src/native/0000755000175000017500000000000011367367570020261 5ustar twernertwernerjinput-20100502/plugins/common/src/native/util.h0000644000175000017500000000466710456267244021417 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #ifdef _MSC_VER #include #else #include #endif extern void printfJava(JNIEnv *env, const char *format, ...); extern void throwRuntimeException(JNIEnv * env, const char *format, ...); extern void throwIOException(JNIEnv * env, const char *format, ...); extern jobject newJObject(JNIEnv * env, const char *class_name, const char *constructor_signature, ...); jinput-20100502/plugins/common/src/native/util.c0000644000175000017500000001107010456267244021374 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include "util.h" static jstring sprintfJavaString(JNIEnv *env, const char *format, va_list ap) { #define BUFFER_SIZE 4000 char buffer[BUFFER_SIZE]; jstring str; #ifdef _MSC_VER vsnprintf_s(buffer, BUFFER_SIZE, _TRUNCATE, format, ap); #else vsnprintf(buffer, BUFFER_SIZE, format, ap); #endif buffer[BUFFER_SIZE - 1] = '\0'; str = (*env)->NewStringUTF(env, buffer); return str; } void printfJava(JNIEnv *env, const char *format, ...) { jstring str; jclass org_lwjgl_LWJGLUtil_class; jmethodID log_method; va_list ap; va_start(ap, format); str = sprintfJavaString(env, format, ap); va_end(ap); org_lwjgl_LWJGLUtil_class = (*env)->FindClass(env, "net/java/games/input/ControllerEnvironment"); if (org_lwjgl_LWJGLUtil_class == NULL) return; log_method = (*env)->GetStaticMethodID(env, org_lwjgl_LWJGLUtil_class, "log", "(Ljava/lang/String;)V"); if (log_method == NULL) return; (*env)->CallStaticVoidMethod(env, org_lwjgl_LWJGLUtil_class, log_method, str); } static void throwException(JNIEnv * env, const char *exception_name, const char *format, va_list ap) { jstring str; jobject exception; if ((*env)->ExceptionCheck(env) == JNI_TRUE) return; // The JVM crashes if we try to throw two exceptions from one native call str = sprintfJavaString(env, format, ap); exception = newJObject(env, exception_name, "(Ljava/lang/String;)V", str); (*env)->Throw(env, exception); } void throwRuntimeException(JNIEnv * env, const char *format, ...) { va_list ap; va_start(ap, format); throwException(env, "java/lang/RuntimeException", format, ap); va_end(ap); } void throwIOException(JNIEnv * env, const char *format, ...) { va_list ap; va_start(ap, format); throwException(env, "java/io/IOException", format, ap); va_end(ap); } jobject newJObject(JNIEnv * env, const char *class_name, const char *constructor_signature, ...) { va_list ap; jclass clazz; jmethodID constructor; jobject obj; clazz = (*env)->FindClass(env, class_name); if (clazz == NULL) return NULL; constructor = (*env)->GetMethodID(env, clazz, "", constructor_signature); if (constructor == NULL) return NULL; va_start(ap, constructor_signature); obj = (*env)->NewObjectV(env, clazz, constructor, ap); va_end(ap); return obj; } jinput-20100502/plugins/windows/0000755000175000017500000000000011367367573016411 5ustar twernertwernerjinput-20100502/plugins/windows/README.txt0000644000175000017500000000337410424764273020105 0ustar twernertwernerThis file modified last on 06/06/2003 by Jeff Kesselman This is the source tree for the core input API. Directory Organization: The root contains a master ANT build.xml. After a successful build you will have the following sub directories: -- apidocs Where the javadocs get built to -- lib Where dependant libraries are kept. -- bin Where the plugin dll and jar files ar built to. -- src The source files. Build instructions: To clean: ant clean To build: ant all (or just ant) To build docs: ant javadoc To test: This build will install the plug-in into the coreAPI's test directories. Use the tests in the coreAPI build.xml to test. Release Info: Initial Release: This release contains an implementation of the input API designed by Mike Martak of Sun and Thomas (?) of Sony CEA for the WIn32 platform. All the code in src/input is cross platform. The Win32 code is segregated to the DirectX plugin (src/DXplugin) which depends on DirectInput from DX7 (or later). 05/09/2003: A number of bugs and problems with the DXPlugin are fixed in this release. This release also brings the code up to date using the DI8 interface. This thus is the first release that requries Peter Puck's DX8 bindings to compile with MinGW. 05/09/2003 (second update): This version adds a new standard value type to the API. Axis.POV holds standard definitions for values for POV (hat) switches -- Axis.POV.CENTER and Axis.POV.OFF are synonmous and are the center position. -- Axis.POV.UP, Axis.POV.DOWN, Axis.POV.LEFT and Axis.POV.RIGHT should be self explainatory. Any hat that claims to be "normalized" will return these values. (It is recommended that all hats be normalized by the systemn specific plugins.) jinput-20100502/plugins/windows/src/0000755000175000017500000000000011367367574017201 5ustar twernertwernerjinput-20100502/plugins/windows/src/native/0000755000175000017500000000000011367367574020467 5ustar twernertwernerjinput-20100502/plugins/windows/src/native/build.xml.mingw0000644000175000017500000000537310457657254023434 0ustar twernertwerner jinput-20100502/plugins/windows/src/native/raw/0000755000175000017500000000000011367367574021260 5ustar twernertwernerjinput-20100502/plugins/windows/src/native/dx8/0000755000175000017500000000000011367367574021172 5ustar twernertwernerjinput-20100502/plugins/windows/src/native/build.xml0000644000175000017500000000672011351124301022261 0ustar twernertwerner jinput-20100502/plugins/windows/src/java/0000755000175000017500000000000011367367573020121 5ustar twernertwernerjinput-20100502/plugins/windows/src/java/net/0000755000175000017500000000000011367367573020707 5ustar twernertwernerjinput-20100502/plugins/windows/src/java/net/java/0000755000175000017500000000000011367367573021630 5ustar twernertwernerjinput-20100502/plugins/windows/src/java/net/java/games/0000755000175000017500000000000011367367573022724 5ustar twernertwernerjinput-20100502/plugins/windows/src/java/net/java/games/input/0000755000175000017500000000000011367367574024064 5ustar twernertwernerjinput-20100502/plugins/windows/src/java/net/java/games/input/RawMouse.java0000644000175000017500000001643110641016004026443 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** * @author elias * @version 1.0 */ final class RawMouse extends Mouse { /* Because one raw event can contain multiple * changes, we'll make a simple state machine * to keep track of which change to report next */ // Another event should be read private final static int EVENT_DONE = 1; // The X axis should be reported next private final static int EVENT_X = 2; // The Y axis should be reported next private final static int EVENT_Y = 3; // The Z axis should be reported next private final static int EVENT_Z = 4; // Button 0 should be reported next private final static int EVENT_BUTTON_0 = 5; // Button 1 should be reported next private final static int EVENT_BUTTON_1 = 6; // Button 2 should be reported next private final static int EVENT_BUTTON_2 = 7; // Button 3 should be reported next private final static int EVENT_BUTTON_3 = 8; // Button 4 should be reported next private final static int EVENT_BUTTON_4 = 9; private final RawDevice device; private final RawMouseEvent current_event = new RawMouseEvent(); private int event_state = EVENT_DONE; protected RawMouse(String name, RawDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) throws IOException { super(name, components, children, rumblers); this.device = device; } public final void pollDevice() throws IOException { device.pollMouse(); } private final static boolean makeButtonEvent(RawMouseEvent mouse_event, Event event, Component button_component, int down_flag, int up_flag) { if ((mouse_event.getButtonFlags() & down_flag) != 0) { event.set(button_component, 1, mouse_event.getNanos()); return true; } else if ((mouse_event.getButtonFlags() & up_flag) != 0) { event.set(button_component, 0, mouse_event.getNanos()); return true; } else return false; } protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException { while (true) { switch (event_state) { case EVENT_DONE: if (!device.getNextMouseEvent(current_event)) return false; event_state = EVENT_X; break; case EVENT_X: int rel_x = device.getEventRelativeX(); event_state = EVENT_Y; if (rel_x != 0) { event.set(getX(), rel_x, current_event.getNanos()); return true; } break; case EVENT_Y: int rel_y = device.getEventRelativeY(); event_state = EVENT_Z; if (rel_y != 0) { event.set(getY(), rel_y, current_event.getNanos()); return true; } break; case EVENT_Z: int wheel = current_event.getWheelDelta(); event_state = EVENT_BUTTON_0; if (wheel != 0) { event.set(getWheel(), wheel, current_event.getNanos()); return true; } break; case EVENT_BUTTON_0: event_state = EVENT_BUTTON_1; if (makeButtonEvent(current_event, event, getPrimaryButton(), RawDevice.RI_MOUSE_BUTTON_1_DOWN, RawDevice.RI_MOUSE_BUTTON_1_UP)) return true; break; case EVENT_BUTTON_1: event_state = EVENT_BUTTON_2; if (makeButtonEvent(current_event, event, getSecondaryButton(), RawDevice.RI_MOUSE_BUTTON_2_DOWN, RawDevice.RI_MOUSE_BUTTON_2_UP)) return true; break; case EVENT_BUTTON_2: event_state = EVENT_BUTTON_3; if (makeButtonEvent(current_event, event, getTertiaryButton(), RawDevice.RI_MOUSE_BUTTON_3_DOWN, RawDevice.RI_MOUSE_BUTTON_3_UP)) return true; break; case EVENT_BUTTON_3: event_state = EVENT_BUTTON_4; if (makeButtonEvent(current_event, event, getButton3(), RawDevice.RI_MOUSE_BUTTON_4_DOWN, RawDevice.RI_MOUSE_BUTTON_4_UP)) return true; break; case EVENT_BUTTON_4: event_state = EVENT_DONE; if (makeButtonEvent(current_event, event, getButton4(), RawDevice.RI_MOUSE_BUTTON_5_DOWN, RawDevice.RI_MOUSE_BUTTON_5_UP)) return true; break; default: throw new RuntimeException("Unknown event state: " + event_state); } } } protected final void setDeviceEventQueueSize(int size) throws IOException { device.setBufferSize(size); } final static class Axis extends AbstractComponent { private final RawDevice device; public Axis(RawDevice device, Component.Identifier.Axis axis) { super(axis.getName(), axis); this.device = device; } public final boolean isRelative() { return true; } public final boolean isAnalog() { return true; } protected final float poll() throws IOException { if (getIdentifier() == Component.Identifier.Axis.X) { return device.getRelativeX(); } else if (getIdentifier() == Component.Identifier.Axis.Y) { return device.getRelativeY(); } else if (getIdentifier() == Component.Identifier.Axis.Z) { return device.getWheel(); } else throw new RuntimeException("Unknown raw axis: " + getIdentifier()); } } final static class Button extends AbstractComponent { private final RawDevice device; private final int button_id; public Button(RawDevice device, Component.Identifier.Button id, int button_id) { super(id.getName(), id); this.device = device; this.button_id = button_id; } protected final float poll() throws IOException { return device.getButtonState(button_id) ? 1 : 0; } public final boolean isAnalog() { return false; } public final boolean isRelative() { return false; } } } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawMouseEvent.java0000644000175000017500000000707210424764301027457 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper of RAWMOUSE * @author elias * @version 1.0 */ final class RawMouseEvent { /* It seems that raw input scales wheel * the same way as direcinput */ private final static int WHEEL_SCALE = 120; private long millis; private int flags; private int button_flags; private int button_data; private long raw_buttons; private long last_x; private long last_y; private long extra_information; public final void set(long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) { this.millis = millis; this.flags = flags; this.button_flags = button_flags; this.button_data = button_data; this.raw_buttons = raw_buttons; this.last_x = last_x; this.last_y = last_y; this.extra_information = extra_information; } public final void set(RawMouseEvent event) { set(event.millis, event.flags, event.button_flags, event.button_data, event.raw_buttons, event.last_x, event.last_y, event.extra_information); } public final int getWheelDelta() { return button_data/WHEEL_SCALE; } private final int getButtonData() { return button_data; } public final int getFlags() { return flags; } public final int getButtonFlags() { return button_flags; } public final int getLastX() { return (int)last_x; } public final int getLastY() { return (int)last_y; } public final long getRawButtons() { return raw_buttons; } public final long getNanos() { return millis*1000000L; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DummyWindow.java0000644000175000017500000000515210424764276027206 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper for a (dummy) window * @author martak * @author elias * @version 1.0 */ final class DummyWindow { private final long hwnd_address; public DummyWindow() throws IOException { this.hwnd_address = createWindow(); } private final static native long createWindow() throws IOException; public final void destroy() throws IOException { nDestroy(hwnd_address); } private final static native void nDestroy(long hwnd_address) throws IOException; public final long getHwnd() { return hwnd_address; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawKeyboard.java0000644000175000017500000001126610424764277027141 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.lang.reflect.Field; import java.lang.reflect.Modifier; /** * @author elias * @version 1.0 */ final class RawKeyboard extends Keyboard { private final RawKeyboardEvent raw_event = new RawKeyboardEvent(); private final RawDevice device; protected RawKeyboard(String name, RawDevice device, Controller[] children, Rumbler[] rumblers) throws IOException { super(name, createKeyboardComponents(device), children, rumblers); this.device = device; } private final static Component[] createKeyboardComponents(RawDevice device) { List components = new ArrayList(); Field[] vkey_fields = RawIdentifierMap.class.getFields(); for (int i = 0; i < vkey_fields.length; i++) { Field vkey_field = vkey_fields[i]; try { if (Modifier.isStatic(vkey_field.getModifiers()) && vkey_field.getType() == int.class) { int vkey_code = vkey_field.getInt(null); Component.Identifier.Key key_id = RawIdentifierMap.mapVKey(vkey_code); if (key_id != Component.Identifier.Key.UNKNOWN) components.add(new Key(device, vkey_code, key_id)); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } return (Component[])components.toArray(new Component[]{}); } protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException { while (true) { if (!device.getNextKeyboardEvent(raw_event)) return false; int vkey = raw_event.getVKey(); Component.Identifier.Key key_id = RawIdentifierMap.mapVKey(vkey); Component key = getComponent(key_id); if (key == null) continue; int message = raw_event.getMessage(); if (message == RawDevice.WM_KEYDOWN || message == RawDevice.WM_SYSKEYDOWN) { event.set(key, 1, raw_event.getNanos()); return true; } else if (message == RawDevice.WM_KEYUP || message == RawDevice.WM_SYSKEYUP) { event.set(key, 0, raw_event.getNanos()); return true; } } } public final void pollDevice() throws IOException { device.pollKeyboard(); } protected final void setDeviceEventQueueSize(int size) throws IOException { device.setBufferSize(size); } final static class Key extends AbstractComponent { private final RawDevice device; private final int vkey_code; public Key(RawDevice device, int vkey_code, Component.Identifier.Key key_id) { super(key_id.getName(), key_id); this.device = device; this.vkey_code = vkey_code; } protected final float poll() throws IOException { return device.isKeyDown(vkey_code) ? 1f : 0f; } public final boolean isAnalog() { return false; } public final boolean isRelative() { return false; } } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DIComponent.java0000644000175000017500000000530610424764274027101 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** * @author elias * @version 1.0 */ final class DIComponent extends AbstractComponent { private final DIDeviceObject object; public DIComponent(Component.Identifier identifier, DIDeviceObject object) { super(object.getName(), identifier); this.object = object; } public final boolean isRelative() { return object.isRelative(); } public final boolean isAnalog() { return object.isAnalog(); } public final float getDeadZone() { return object.getDeadzone(); } public final DIDeviceObject getDeviceObject() { return object; } protected final float poll() throws IOException { return DIControllers.poll(this, object); } } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawDevice.java0000644000175000017500000002650410424764276026600 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper of RAWDEVICELIST * @author elias * @version 1.0 */ final class RawDevice { public final static int RI_MOUSE_LEFT_BUTTON_DOWN = 0x0001; // Left Button changed to down. public final static int RI_MOUSE_LEFT_BUTTON_UP = 0x0002; // Left Button changed to up. public final static int RI_MOUSE_RIGHT_BUTTON_DOWN = 0x0004; // Right Button changed to down. public final static int RI_MOUSE_RIGHT_BUTTON_UP = 0x0008; // Right Button changed to up. public final static int RI_MOUSE_MIDDLE_BUTTON_DOWN = 0x0010; // Middle Button changed to down. public final static int RI_MOUSE_MIDDLE_BUTTON_UP = 0x0020; // Middle Button changed to up. public final static int RI_MOUSE_BUTTON_1_DOWN = RI_MOUSE_LEFT_BUTTON_DOWN; public final static int RI_MOUSE_BUTTON_1_UP = RI_MOUSE_LEFT_BUTTON_UP; public final static int RI_MOUSE_BUTTON_2_DOWN = RI_MOUSE_RIGHT_BUTTON_DOWN; public final static int RI_MOUSE_BUTTON_2_UP = RI_MOUSE_RIGHT_BUTTON_UP; public final static int RI_MOUSE_BUTTON_3_DOWN = RI_MOUSE_MIDDLE_BUTTON_DOWN; public final static int RI_MOUSE_BUTTON_3_UP = RI_MOUSE_MIDDLE_BUTTON_UP; public final static int RI_MOUSE_BUTTON_4_DOWN = 0x0040; public final static int RI_MOUSE_BUTTON_4_UP = 0x0080; public final static int RI_MOUSE_BUTTON_5_DOWN = 0x0100; public final static int RI_MOUSE_BUTTON_5_UP = 0x0200; /* * If usButtonFlags has RI_MOUSE_WHEEL, the wheel delta is stored in usButtonData. * Take it as a signed value. */ public final static int RI_MOUSE_WHEEL = 0x0400; public final static int MOUSE_MOVE_RELATIVE = 0; public final static int MOUSE_MOVE_ABSOLUTE = 1; public final static int MOUSE_VIRTUAL_DESKTOP = 0x02; // the coordinates are mapped to the virtual desktop public final static int MOUSE_ATTRIBUTES_CHANGED = 0x04; // requery for mouse attributes public final static int RIM_TYPEHID = 2; public final static int RIM_TYPEKEYBOARD = 1; public final static int RIM_TYPEMOUSE = 0; public final static int WM_KEYDOWN = 0x0100; public final static int WM_KEYUP = 0x0101; public final static int WM_SYSKEYDOWN = 0x0104; public final static int WM_SYSKEYUP = 0x0105; private final RawInputEventQueue queue; private final long handle; private final int type; /* Events from the event queue thread end here */ private DataQueue keyboard_events; private DataQueue mouse_events; /* After processing in poll*(), the events are placed here */ private DataQueue processed_keyboard_events; private DataQueue processed_mouse_events; /* mouse state */ private final boolean[] button_states = new boolean[5]; private int wheel; private int relative_x; private int relative_y; private int last_x; private int last_y; // Last x, y for converting absolute events to relative private int event_relative_x; private int event_relative_y; private int event_last_x; private int event_last_y; /* keyboard state */ private final boolean[] key_states = new boolean[0xFF]; public RawDevice(RawInputEventQueue queue, long handle, int type) { this.queue = queue; this.handle = handle; this.type = type; setBufferSize(AbstractController.EVENT_QUEUE_DEPTH); } /* Careful, this is called from the event queue thread */ public final synchronized void addMouseEvent(long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) { if (mouse_events.hasRemaining()) { RawMouseEvent event = (RawMouseEvent)mouse_events.get(); event.set(millis, flags, button_flags, button_data, raw_buttons, last_x, last_y, extra_information); } } /* Careful, this is called from the event queue thread */ public final synchronized void addKeyboardEvent(long millis, int make_code, int flags, int vkey, int message, long extra_information) { if (keyboard_events.hasRemaining()) { RawKeyboardEvent event = (RawKeyboardEvent)keyboard_events.get(); event.set(millis, make_code, flags, vkey, message, extra_information); } } public final synchronized void pollMouse() { relative_x = relative_y = wheel = 0; mouse_events.flip(); while (mouse_events.hasRemaining()) { RawMouseEvent event = (RawMouseEvent)mouse_events.get(); boolean has_update = processMouseEvent(event); if (has_update && processed_mouse_events.hasRemaining()) { RawMouseEvent processed_event = (RawMouseEvent)processed_mouse_events.get(); processed_event.set(event); } } mouse_events.compact(); } public final synchronized void pollKeyboard() { keyboard_events.flip(); while (keyboard_events.hasRemaining()) { RawKeyboardEvent event = (RawKeyboardEvent)keyboard_events.get(); boolean has_update = processKeyboardEvent(event); if (has_update && processed_keyboard_events.hasRemaining()) { RawKeyboardEvent processed_event = (RawKeyboardEvent)processed_keyboard_events.get(); processed_event.set(event); } } keyboard_events.compact(); } private final boolean updateButtonState(int button_id, int button_flags, int down_flag, int up_flag) { if (button_id >= button_states.length) return false; if ((button_flags & down_flag) != 0) { button_states[button_id] = true; return true; } else if ((button_flags & up_flag) != 0) { button_states[button_id] = false; return true; } else return false; } private final boolean processKeyboardEvent(RawKeyboardEvent event) { int message = event.getMessage(); int vkey = event.getVKey(); if (vkey >= key_states.length) return false; if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) { key_states[vkey] = true; return true; } else if (message == WM_KEYUP || message == WM_SYSKEYUP) { key_states[vkey] = false; return true; } else return false; } public final boolean isKeyDown(int vkey) { return key_states[vkey]; } private final boolean processMouseEvent(RawMouseEvent event) { boolean has_update = false; int button_flags = event.getButtonFlags(); has_update = updateButtonState(0, button_flags, RI_MOUSE_BUTTON_1_DOWN, RI_MOUSE_BUTTON_1_UP) || has_update; has_update = updateButtonState(1, button_flags, RI_MOUSE_BUTTON_2_DOWN, RI_MOUSE_BUTTON_2_UP) || has_update; has_update = updateButtonState(2, button_flags, RI_MOUSE_BUTTON_3_DOWN, RI_MOUSE_BUTTON_3_UP) || has_update; has_update = updateButtonState(3, button_flags, RI_MOUSE_BUTTON_4_DOWN, RI_MOUSE_BUTTON_4_UP) || has_update; has_update = updateButtonState(4, button_flags, RI_MOUSE_BUTTON_5_DOWN, RI_MOUSE_BUTTON_5_UP) || has_update; int dx; int dy; if ((event.getFlags() & MOUSE_MOVE_ABSOLUTE) != 0) { dx = event.getLastX() - last_x; dy = event.getLastY() - last_y; last_x = event.getLastX(); last_y = event.getLastY(); } else { dx = event.getLastX(); dy = event.getLastY(); } int dwheel = 0; if ((button_flags & RI_MOUSE_WHEEL) != 0) dwheel = event.getWheelDelta(); relative_x += dx; relative_y += dy; wheel += dwheel; has_update = dx != 0 || dy != 0 || dwheel != 0 || has_update; return has_update; } public final int getWheel() { return wheel; } public final int getEventRelativeX() { return event_relative_x; } public final int getEventRelativeY() { return event_relative_y; } public final int getRelativeX() { return relative_x; } public final int getRelativeY() { return relative_y; } public final synchronized boolean getNextKeyboardEvent(RawKeyboardEvent event) { processed_keyboard_events.flip(); if (!processed_keyboard_events.hasRemaining()) { processed_keyboard_events.compact(); return false; } RawKeyboardEvent next_event = (RawKeyboardEvent)processed_keyboard_events.get(); event.set(next_event); processed_keyboard_events.compact(); return true; } public final synchronized boolean getNextMouseEvent(RawMouseEvent event) { processed_mouse_events.flip(); if (!processed_mouse_events.hasRemaining()) { processed_mouse_events.compact(); return false; } RawMouseEvent next_event = (RawMouseEvent)processed_mouse_events.get(); if ((next_event.getFlags() & MOUSE_MOVE_ABSOLUTE) != 0) { event_relative_x = next_event.getLastX() - event_last_x; event_relative_y = next_event.getLastY() - event_last_y; event_last_x = next_event.getLastX(); event_last_y = next_event.getLastY(); } else { event_relative_x = next_event.getLastX(); event_relative_y = next_event.getLastY(); } event.set(next_event); processed_mouse_events.compact(); return true; } public final boolean getButtonState(int button_id) { if (button_id >= button_states.length) return false; return button_states[button_id]; } public final void setBufferSize(int size) { keyboard_events = new DataQueue(size, RawKeyboardEvent.class); mouse_events = new DataQueue(size, RawMouseEvent.class); processed_keyboard_events = new DataQueue(size, RawKeyboardEvent.class); processed_mouse_events = new DataQueue(size, RawMouseEvent.class); } public final int getType() { return type; } public final long getHandle() { return handle; } public final String getName() throws IOException { return nGetName(handle); } private final static native String nGetName(long handle) throws IOException; public final RawDeviceInfo getInfo() throws IOException { return nGetInfo(this, handle); } private final static native RawDeviceInfo nGetInfo(RawDevice device, long handle) throws IOException; } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawInputEnvironmentPlugin.java0000644000175000017500000001742711164715231032075 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.List; import java.util.ArrayList; import java.io.File; import java.io.IOException; import net.java.games.util.plugins.Plugin; /** DirectInput implementation of controller environment * @author martak * @author elias * @version 1.0 */ public final class RawInputEnvironmentPlugin extends ControllerEnvironment implements Plugin { private static boolean supported = false; /** * Static utility method for loading native libraries. * It will try to load from either the path given by * the net.java.games.input.librarypath property * or through System.loadLibrary(). * */ static void loadLibrary(final String lib_name) { AccessController.doPrivileged( new PrivilegedAction() { public final Object run() { try { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); else System.loadLibrary(lib_name); } catch (UnsatisfiedLinkError e) { e.printStackTrace(); supported = false; } return null; } }); } static String getPrivilegedProperty(final String property) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property); } }); } static String getPrivilegedProperty(final String property, final String default_value) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property, default_value); } }); } static { String osName = getPrivilegedProperty("os.name", "").trim(); if(osName.startsWith("Windows")) { supported = true; if("x86".equals(getPrivilegedProperty("os.arch"))) { loadLibrary("jinput-raw"); } else { loadLibrary("jinput-raw_64"); } } } private final Controller[] controllers; /** Creates new DirectInputEnvironment */ public RawInputEnvironmentPlugin() { RawInputEventQueue queue; Controller[] controllers = new Controller[]{}; if(isSupported()) { try { queue = new RawInputEventQueue(); controllers = enumControllers(queue); } catch (IOException e) { logln("Failed to enumerate devices: " + e.getMessage()); } } this.controllers = controllers; } public final Controller[] getControllers() { return controllers; } private final static SetupAPIDevice lookupSetupAPIDevice(String device_name, List setupapi_devices) { /* First, replace # with / in the device name, since that * seems to be the format in raw input device name */ device_name = device_name.replaceAll("#", "\\\\").toUpperCase(); for (int i = 0; i < setupapi_devices.size(); i++) { SetupAPIDevice device = (SetupAPIDevice)setupapi_devices.get(i); if (device_name.indexOf(device.getInstanceId().toUpperCase()) != -1) return device; } return null; } private final static void createControllersFromDevices(RawInputEventQueue queue, List controllers, List devices, List setupapi_devices) throws IOException { List active_devices = new ArrayList(); for (int i = 0; i < devices.size(); i++) { RawDevice device = (RawDevice)devices.get(i); SetupAPIDevice setupapi_device = lookupSetupAPIDevice(device.getName(), setupapi_devices); if (setupapi_device == null) { /* Either the device is an RDP or we failed to locate the * SetupAPI device that matches */ continue; } RawDeviceInfo info = device.getInfo(); Controller controller = info.createControllerFromDevice(device, setupapi_device); if (controller != null) { controllers.add(controller); active_devices.add(device); } } queue.start(active_devices); } private final static native void enumerateDevices(RawInputEventQueue queue, List devices) throws IOException; private final Controller[] enumControllers(RawInputEventQueue queue) throws IOException { List controllers = new ArrayList(); List devices = new ArrayList(); enumerateDevices(queue, devices); List setupapi_devices = enumSetupAPIDevices(); createControllersFromDevices(queue, controllers, devices, setupapi_devices); Controller[] controllers_array = new Controller[controllers.size()]; controllers.toArray(controllers_array); return controllers_array; } public boolean isSupported() { return supported; } /* * The raw input API, while being able to access * multiple mice and keyboards, is a bit raw (hah) * since it lacks some important features: * * 1. The list of keyboards and the list of mice * both include useless Terminal Server * devices (RDP_MOU and RDP_KEY) that we'd * like to skip. * 2. The device names returned by GetRawInputDeviceInfo() * are not for display, but instead synthesized * from a combination of a device instance id * and a GUID. * * A solution to both problems is the SetupAPI that allows * us to enumerate all keyboard and mouse devices and fetch their * descriptive names and at the same time filter out the unwanted * RDP devices. */ private final static List enumSetupAPIDevices() throws IOException { List devices = new ArrayList(); nEnumSetupAPIDevices(getKeyboardClassGUID(), devices); nEnumSetupAPIDevices(getMouseClassGUID(), devices); return devices; } private final static native void nEnumSetupAPIDevices(byte[] guid, List devices) throws IOException; private final static native byte[] getKeyboardClassGUID(); private final static native byte[] getMouseClassGUID(); } // class DirectInputEnvironment jinput-20100502/plugins/windows/src/java/net/java/games/input/DIMouse.java0000644000175000017500000000531310424764275026226 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** * @author elias * @version 1.0 */ final class DIMouse extends Mouse { private final IDirectInputDevice device; protected DIMouse(IDirectInputDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) { super(device.getProductName(), components, children, rumblers); this.device = device; } public final void pollDevice() throws IOException { device.pollAll(); } protected final boolean getNextDeviceEvent(Event event) throws IOException { return DIControllers.getNextDeviceEvent(event, device); } protected final void setDeviceEventQueueSize(int size) throws IOException { device.setBufferSize(size); } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DIEffectInfo.java0000644000175000017500000000600210424764275027142 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** Java wrapper for DIEFFECTINFO * @author elias * @version 1.0 */ final class DIEffectInfo { private final IDirectInputDevice device; private final byte[] guid; private final int guid_id; private final int effect_type; private final int static_params; private final int dynamic_params; private final String name; public DIEffectInfo(IDirectInputDevice device, byte[] guid, int guid_id, int effect_type, int static_params, int dynamic_params, String name) { this.device = device; this.guid = guid; this.guid_id = guid_id; this.effect_type = effect_type; this.static_params = static_params; this.dynamic_params = dynamic_params; this.name = name; } public final byte[] getGUID() { return guid; } public final int getGUIDId() { return guid_id; } public final int getDynamicParams() { return dynamic_params; } public final int getEffectType() { return effect_type; } public final String getName() { return name; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DIAbstractController.java0000644000175000017500000000557510424764274030756 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** * @author elias * @version 1.0 */ final class DIAbstractController extends AbstractController { private final IDirectInputDevice device; private final Controller.Type type; protected DIAbstractController(IDirectInputDevice device, Component[] components, Controller[] children, Rumbler[] rumblers, Controller.Type type) { super(device.getProductName(), components, children, rumblers); this.device = device; this.type = type; } public final void pollDevice() throws IOException { device.pollAll(); } protected final boolean getNextDeviceEvent(Event event) throws IOException { return DIControllers.getNextDeviceEvent(event, device); } protected final void setDeviceEventQueueSize(int size) throws IOException { device.setBufferSize(size); } public final Controller.Type getType() { return type; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootjinput-20100502/plugins/windows/src/java/net/java/games/input/DirectAndRawInputEnvironmentPlugin.javajinput-20100502/plugins/windows/src/java/net/java/games/input/DirectAndRawInputEnvironmentPlugin.jav0000644000175000017500000000674310654435377033526 0ustar twernertwerner/** * Copyright (C) 2007 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.util.ArrayList; import java.util.List; /** * Combines the list of seperate keyboards and mice found with the raw plugin, * with the game controllers found with direct input. * * @author Jeremy */ public class DirectAndRawInputEnvironmentPlugin extends ControllerEnvironment { private RawInputEnvironmentPlugin rawPlugin; private DirectInputEnvironmentPlugin dinputPlugin; private Controller[] controllers = null; public DirectAndRawInputEnvironmentPlugin() { // These two *must* be loaded in this order for raw devices to work. dinputPlugin = new DirectInputEnvironmentPlugin(); rawPlugin = new RawInputEnvironmentPlugin(); } /** * @see net.java.games.input.ControllerEnvironment#getControllers() */ public Controller[] getControllers() { if(controllers == null) { boolean rawKeyboardFound = false; boolean rawMouseFound = false; List tempControllers = new ArrayList(); Controller[] dinputControllers = dinputPlugin.getControllers(); Controller[] rawControllers = rawPlugin.getControllers(); for(int i=0;i= 0 && int_value < slice) return Component.POV.UP; else if (int_value < 3*slice) return Component.POV.UP_RIGHT; else if (int_value < 5*slice) return Component.POV.RIGHT; else if (int_value < 7*slice) return Component.POV.DOWN_RIGHT; else if (int_value < 9*slice) return Component.POV.DOWN; else if (int_value < 11*slice) return Component.POV.DOWN_LEFT; else if (int_value < 13*slice) return Component.POV.LEFT; else if (int_value < 15*slice) return Component.POV.UP_LEFT; else return Component.POV.UP; } else if (isAxis() && !isRelative()) { return 2*(value - min)/(float)(max - min) - 1; } else return value; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawInputEventQueue.java0000644000175000017500000001242610424764277030506 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; /** Java wrapper of RAWDEVICELIST * @author elias * @version 1.0 */ final class RawInputEventQueue { private final Object monitor = new Object(); private List devices; public final void start(List devices) throws IOException { this.devices = devices; QueueThread queue = new QueueThread(); synchronized (monitor) { queue.start(); // wait for initialization while (!queue.isInitialized()) { try { monitor.wait(); } catch (InterruptedException e) {} } } if (queue.getException() != null) throw queue.getException(); } private final RawDevice lookupDevice(long handle) { for (int i = 0; i < devices.size(); i++) { RawDevice device = (RawDevice)devices.get(i); if (device.getHandle() == handle) return device; } return null; } /* Event methods called back from native code in nPoll() */ private final void addMouseEvent(long handle, long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) { RawDevice device = lookupDevice(handle); if (device == null) return; device.addMouseEvent(millis, flags, button_flags, button_data, raw_buttons, last_x, last_y, extra_information); } private final void addKeyboardEvent(long handle, long millis, int make_code, int flags, int vkey, int message, long extra_information) { RawDevice device = lookupDevice(handle); if (device == null) return; device.addKeyboardEvent(millis, make_code, flags, vkey, message, extra_information); } private final void poll(DummyWindow window) throws IOException { nPoll(window.getHwnd()); } private final native void nPoll(long hwnd_handle) throws IOException; private final static void registerDevices(DummyWindow window, RawDeviceInfo[] devices) throws IOException { nRegisterDevices(0, window.getHwnd(), devices); } private final static native void nRegisterDevices(int flags, long hwnd_addr, RawDeviceInfo[] devices) throws IOException; private final class QueueThread extends Thread { private boolean initialized; private DummyWindow window; private IOException exception; public QueueThread() { setDaemon(true); } public final boolean isInitialized() { return initialized; } public final IOException getException() { return exception; } public final void run() { // We have to create the window in the (private) queue thread try { window = new DummyWindow(); } catch (IOException e) { exception = e; } initialized = true; synchronized (monitor) { monitor.notify(); } if (exception != null) return; Set active_infos = new HashSet(); try { for (int i = 0; i < devices.size(); i++) { RawDevice device = (RawDevice)devices.get(i); active_infos.add(device.getInfo()); } RawDeviceInfo[] active_infos_array = new RawDeviceInfo[active_infos.size()]; active_infos.toArray(active_infos_array); try { registerDevices(window, active_infos_array); while (!isInterrupted()) { poll(window); } } finally { window.destroy(); } } catch (IOException e) { exception = e; } } } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DIIdentifierMap.java0000644000175000017500000005044610424764275027665 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * @author elias * @version 1.0 */ final class DIIdentifierMap { public final static int DIK_ESCAPE = 0x01; public final static int DIK_1 = 0x02; public final static int DIK_2 = 0x03; public final static int DIK_3 = 0x04; public final static int DIK_4 = 0x05; public final static int DIK_5 = 0x06; public final static int DIK_6 = 0x07; public final static int DIK_7 = 0x08; public final static int DIK_8 = 0x09; public final static int DIK_9 = 0x0A; public final static int DIK_0 = 0x0B; public final static int DIK_MINUS = 0x0C; /* - on main keyboard */ public final static int DIK_EQUALS = 0x0D; public final static int DIK_BACK = 0x0E; /* backspace */ public final static int DIK_TAB = 0x0F; public final static int DIK_Q = 0x10; public final static int DIK_W = 0x11; public final static int DIK_E = 0x12; public final static int DIK_R = 0x13; public final static int DIK_T = 0x14; public final static int DIK_Y = 0x15; public final static int DIK_U = 0x16; public final static int DIK_I = 0x17; public final static int DIK_O = 0x18; public final static int DIK_P = 0x19; public final static int DIK_LBRACKET = 0x1A; public final static int DIK_RBRACKET = 0x1B; public final static int DIK_RETURN = 0x1C; /* Enter on main keyboard */ public final static int DIK_LCONTROL = 0x1D; public final static int DIK_A = 0x1E; public final static int DIK_S = 0x1F; public final static int DIK_D = 0x20; public final static int DIK_F = 0x21; public final static int DIK_G = 0x22; public final static int DIK_H = 0x23; public final static int DIK_J = 0x24; public final static int DIK_K = 0x25; public final static int DIK_L = 0x26; public final static int DIK_SEMICOLON = 0x27; public final static int DIK_APOSTROPHE = 0x28; public final static int DIK_GRAVE = 0x29; /* accent grave */ public final static int DIK_LSHIFT = 0x2A; public final static int DIK_BACKSLASH = 0x2B; public final static int DIK_Z = 0x2C; public final static int DIK_X = 0x2D; public final static int DIK_C = 0x2E; public final static int DIK_V = 0x2F; public final static int DIK_B = 0x30; public final static int DIK_N = 0x31; public final static int DIK_M = 0x32; public final static int DIK_COMMA = 0x33; public final static int DIK_PERIOD = 0x34; /* . on main keyboard */ public final static int DIK_SLASH = 0x35; /* / on main keyboard */ public final static int DIK_RSHIFT = 0x36; public final static int DIK_MULTIPLY = 0x37; /* * on numeric keypad */ public final static int DIK_LMENU = 0x38; /* left Alt */ public final static int DIK_SPACE = 0x39; public final static int DIK_CAPITAL = 0x3A; public final static int DIK_F1 = 0x3B; public final static int DIK_F2 = 0x3C; public final static int DIK_F3 = 0x3D; public final static int DIK_F4 = 0x3E; public final static int DIK_F5 = 0x3F; public final static int DIK_F6 = 0x40; public final static int DIK_F7 = 0x41; public final static int DIK_F8 = 0x42; public final static int DIK_F9 = 0x43; public final static int DIK_F10 = 0x44; public final static int DIK_NUMLOCK = 0x45; public final static int DIK_SCROLL = 0x46; /* Scroll Lock */ public final static int DIK_NUMPAD7 = 0x47; public final static int DIK_NUMPAD8 = 0x48; public final static int DIK_NUMPAD9 = 0x49; public final static int DIK_SUBTRACT = 0x4A; /* - on numeric keypad */ public final static int DIK_NUMPAD4 = 0x4B; public final static int DIK_NUMPAD5 = 0x4C; public final static int DIK_NUMPAD6 = 0x4D; public final static int DIK_ADD = 0x4E; /* + on numeric keypad */ public final static int DIK_NUMPAD1 = 0x4F; public final static int DIK_NUMPAD2 = 0x50; public final static int DIK_NUMPAD3 = 0x51; public final static int DIK_NUMPAD0 = 0x52; public final static int DIK_DECIMAL = 0x53; /* . on numeric keypad */ public final static int DIK_OEM_102 = 0x56; /* <> or \| on RT 102-key keyboard (Non-U.S.) */ public final static int DIK_F11 = 0x57; public final static int DIK_F12 = 0x58; public final static int DIK_F13 = 0x64; /* (NEC PC98) */ public final static int DIK_F14 = 0x65; /* (NEC PC98) */ public final static int DIK_F15 = 0x66; /* (NEC PC98) */ public final static int DIK_KANA = 0x70; /* (Japanese keyboard) */ public final static int DIK_ABNT_C1 = 0x73; /* /? on Brazilian keyboard */ public final static int DIK_CONVERT = 0x79; /* (Japanese keyboard) */ public final static int DIK_NOCONVERT = 0x7B; /* (Japanese keyboard) */ public final static int DIK_YEN = 0x7D; /* (Japanese keyboard) */ public final static int DIK_ABNT_C2 = 0x7E; /* Numpad . on Brazilian keyboard */ public final static int DIK_NUMPADEQUALS = 0x8D; /* = on numeric keypad (NEC PC98) */ public final static int DIK_PREVTRACK = 0x90; /* Previous Track (DIK_CIRCUMFLEX on Japanese keyboard) */ public final static int DIK_AT = 0x91; /* (NEC PC98) */ public final static int DIK_COLON = 0x92; /* (NEC PC98) */ public final static int DIK_UNDERLINE = 0x93; /* (NEC PC98) */ public final static int DIK_KANJI = 0x94; /* (Japanese keyboard) */ public final static int DIK_STOP = 0x95; /* (NEC PC98) */ public final static int DIK_AX = 0x96; /* (Japan AX) */ public final static int DIK_UNLABELED = 0x97; /* (J3100) */ public final static int DIK_NEXTTRACK = 0x99; /* Next Track */ public final static int DIK_NUMPADENTER = 0x9C; /* Enter on numeric keypad */ public final static int DIK_RCONTROL = 0x9D; public final static int DIK_MUTE = 0xA0; /* Mute */ public final static int DIK_CALCULATOR = 0xA1; /* Calculator */ public final static int DIK_PLAYPAUSE = 0xA2; /* Play / Pause */ public final static int DIK_MEDIASTOP = 0xA4; /* Media Stop */ public final static int DIK_VOLUMEDOWN = 0xAE; /* Volume - */ public final static int DIK_VOLUMEUP = 0xB0; /* Volume + */ public final static int DIK_WEBHOME = 0xB2; /* Web home */ public final static int DIK_NUMPADCOMMA = 0xB3; /* , on numeric keypad (NEC PC98) */ public final static int DIK_DIVIDE = 0xB5; /* / on numeric keypad */ public final static int DIK_SYSRQ = 0xB7; public final static int DIK_RMENU = 0xB8; /* right Alt */ public final static int DIK_PAUSE = 0xC5; /* Pause */ public final static int DIK_HOME = 0xC7; /* Home on arrow keypad */ public final static int DIK_UP = 0xC8; /* UpArrow on arrow keypad */ public final static int DIK_PRIOR = 0xC9; /* PgUp on arrow keypad */ public final static int DIK_LEFT = 0xCB; /* LeftArrow on arrow keypad */ public final static int DIK_RIGHT = 0xCD; /* RightArrow on arrow keypad */ public final static int DIK_END = 0xCF; /* End on arrow keypad */ public final static int DIK_DOWN = 0xD0; /* DownArrow on arrow keypad */ public final static int DIK_NEXT = 0xD1; /* PgDn on arrow keypad */ public final static int DIK_INSERT = 0xD2; /* Insert on arrow keypad */ public final static int DIK_DELETE = 0xD3; /* Delete on arrow keypad */ public final static int DIK_LWIN = 0xDB; /* Left Windows key */ public final static int DIK_RWIN = 0xDC; /* Right Windows key */ public final static int DIK_APPS = 0xDD; /* AppMenu key */ public final static int DIK_POWER = 0xDE; /* System Power */ public final static int DIK_SLEEP = 0xDF; /* System Sleep */ public final static int DIK_WAKE = 0xE3; /* System Wake */ public final static int DIK_WEBSEARCH = 0xE5; /* Web Search */ public final static int DIK_WEBFAVORITES = 0xE6; /* Web Favorites */ public final static int DIK_WEBREFRESH = 0xE7; /* Web Refresh */ public final static int DIK_WEBSTOP = 0xE8; /* Web Stop */ public final static int DIK_WEBFORWARD = 0xE9; /* Web Forward */ public final static int DIK_WEBBACK = 0xEA; /* Web Back */ public final static int DIK_MYCOMPUTER = 0xEB; /* My Computer */ public final static int DIK_MAIL = 0xEC; /* Mail */ public final static int DIK_MEDIASELECT = 0xED; /* Media Select */ public final static Component.Identifier.Key getKeyIdentifier(int key_code) { switch (key_code) { case DIK_ESCAPE: return Component.Identifier.Key.ESCAPE; case DIK_1: return Component.Identifier.Key._1; case DIK_2: return Component.Identifier.Key._2; case DIK_3: return Component.Identifier.Key._3; case DIK_4: return Component.Identifier.Key._4; case DIK_5: return Component.Identifier.Key._5; case DIK_6: return Component.Identifier.Key._6; case DIK_7: return Component.Identifier.Key._7; case DIK_8: return Component.Identifier.Key._8; case DIK_9: return Component.Identifier.Key._9; case DIK_0: return Component.Identifier.Key._0; case DIK_MINUS: return Component.Identifier.Key.MINUS; case DIK_EQUALS: return Component.Identifier.Key.EQUALS; case DIK_BACK: return Component.Identifier.Key.BACK; case DIK_TAB: return Component.Identifier.Key.TAB; case DIK_Q: return Component.Identifier.Key.Q; case DIK_W: return Component.Identifier.Key.W; case DIK_E: return Component.Identifier.Key.E; case DIK_R: return Component.Identifier.Key.R; case DIK_T: return Component.Identifier.Key.T; case DIK_Y: return Component.Identifier.Key.Y; case DIK_U: return Component.Identifier.Key.U; case DIK_I: return Component.Identifier.Key.I; case DIK_O: return Component.Identifier.Key.O; case DIK_P: return Component.Identifier.Key.P; case DIK_LBRACKET: return Component.Identifier.Key.LBRACKET; case DIK_RBRACKET: return Component.Identifier.Key.RBRACKET; case DIK_RETURN: return Component.Identifier.Key.RETURN; case DIK_LCONTROL: return Component.Identifier.Key.LCONTROL; case DIK_A: return Component.Identifier.Key.A; case DIK_S: return Component.Identifier.Key.S; case DIK_D: return Component.Identifier.Key.D; case DIK_F: return Component.Identifier.Key.F; case DIK_G: return Component.Identifier.Key.G; case DIK_H: return Component.Identifier.Key.H; case DIK_J: return Component.Identifier.Key.J; case DIK_K: return Component.Identifier.Key.K; case DIK_L: return Component.Identifier.Key.L; case DIK_SEMICOLON: return Component.Identifier.Key.SEMICOLON; case DIK_APOSTROPHE: return Component.Identifier.Key.APOSTROPHE; case DIK_GRAVE: return Component.Identifier.Key.GRAVE; case DIK_LSHIFT: return Component.Identifier.Key.LSHIFT; case DIK_BACKSLASH: return Component.Identifier.Key.BACKSLASH; case DIK_Z: return Component.Identifier.Key.Z; case DIK_X: return Component.Identifier.Key.X; case DIK_C: return Component.Identifier.Key.C; case DIK_V: return Component.Identifier.Key.V; case DIK_B: return Component.Identifier.Key.B; case DIK_N: return Component.Identifier.Key.N; case DIK_M: return Component.Identifier.Key.M; case DIK_COMMA: return Component.Identifier.Key.COMMA; case DIK_PERIOD: return Component.Identifier.Key.PERIOD; case DIK_SLASH: return Component.Identifier.Key.SLASH; case DIK_RSHIFT: return Component.Identifier.Key.RSHIFT; case DIK_MULTIPLY: return Component.Identifier.Key.MULTIPLY; case DIK_LMENU: return Component.Identifier.Key.LALT; case DIK_SPACE: return Component.Identifier.Key.SPACE; case DIK_CAPITAL: return Component.Identifier.Key.CAPITAL; case DIK_F1: return Component.Identifier.Key.F1; case DIK_F2: return Component.Identifier.Key.F2; case DIK_F3: return Component.Identifier.Key.F3; case DIK_F4: return Component.Identifier.Key.F4; case DIK_F5: return Component.Identifier.Key.F5; case DIK_F6: return Component.Identifier.Key.F6; case DIK_F7: return Component.Identifier.Key.F7; case DIK_F8: return Component.Identifier.Key.F8; case DIK_F9: return Component.Identifier.Key.F9; case DIK_F10: return Component.Identifier.Key.F10; case DIK_NUMLOCK: return Component.Identifier.Key.NUMLOCK; case DIK_SCROLL: return Component.Identifier.Key.SCROLL; case DIK_NUMPAD7: return Component.Identifier.Key.NUMPAD7; case DIK_NUMPAD8: return Component.Identifier.Key.NUMPAD8; case DIK_NUMPAD9: return Component.Identifier.Key.NUMPAD9; case DIK_SUBTRACT: return Component.Identifier.Key.SUBTRACT; case DIK_NUMPAD4: return Component.Identifier.Key.NUMPAD4; case DIK_NUMPAD5: return Component.Identifier.Key.NUMPAD5; case DIK_NUMPAD6: return Component.Identifier.Key.NUMPAD6; case DIK_ADD: return Component.Identifier.Key.ADD; case DIK_NUMPAD1: return Component.Identifier.Key.NUMPAD1; case DIK_NUMPAD2: return Component.Identifier.Key.NUMPAD2; case DIK_NUMPAD3: return Component.Identifier.Key.NUMPAD3; case DIK_NUMPAD0: return Component.Identifier.Key.NUMPAD0; case DIK_DECIMAL: return Component.Identifier.Key.DECIMAL; case DIK_F11: return Component.Identifier.Key.F11; case DIK_F12: return Component.Identifier.Key.F12; case DIK_F13: return Component.Identifier.Key.F13; case DIK_F14: return Component.Identifier.Key.F14; case DIK_F15: return Component.Identifier.Key.F15; case DIK_KANA: return Component.Identifier.Key.KANA; case DIK_CONVERT: return Component.Identifier.Key.CONVERT; case DIK_NOCONVERT: return Component.Identifier.Key.NOCONVERT; case DIK_YEN: return Component.Identifier.Key.YEN; case DIK_NUMPADEQUALS: return Component.Identifier.Key.NUMPADEQUAL; case DIK_AT: return Component.Identifier.Key.AT; case DIK_COLON: return Component.Identifier.Key.COLON; case DIK_UNDERLINE: return Component.Identifier.Key.UNDERLINE; case DIK_KANJI: return Component.Identifier.Key.KANJI; case DIK_STOP: return Component.Identifier.Key.STOP; case DIK_AX: return Component.Identifier.Key.AX; case DIK_UNLABELED: return Component.Identifier.Key.UNLABELED; case DIK_NUMPADENTER: return Component.Identifier.Key.NUMPADENTER; case DIK_RCONTROL: return Component.Identifier.Key.RCONTROL; case DIK_NUMPADCOMMA: return Component.Identifier.Key.NUMPADCOMMA; case DIK_DIVIDE: return Component.Identifier.Key.DIVIDE; case DIK_SYSRQ: return Component.Identifier.Key.SYSRQ; case DIK_RMENU: return Component.Identifier.Key.RALT; case DIK_PAUSE: return Component.Identifier.Key.PAUSE; case DIK_HOME: return Component.Identifier.Key.HOME; case DIK_UP: return Component.Identifier.Key.UP; case DIK_PRIOR: return Component.Identifier.Key.PAGEUP; case DIK_LEFT: return Component.Identifier.Key.LEFT; case DIK_RIGHT: return Component.Identifier.Key.RIGHT; case DIK_END: return Component.Identifier.Key.END; case DIK_DOWN: return Component.Identifier.Key.DOWN; case DIK_NEXT: return Component.Identifier.Key.PAGEDOWN; case DIK_INSERT: return Component.Identifier.Key.INSERT; case DIK_DELETE: return Component.Identifier.Key.DELETE; case DIK_LWIN: return Component.Identifier.Key.LWIN; case DIK_RWIN: return Component.Identifier.Key.RWIN; case DIK_APPS: return Component.Identifier.Key.APPS; case DIK_POWER: return Component.Identifier.Key.POWER; case DIK_SLEEP: return Component.Identifier.Key.SLEEP; /* Unassigned keys */ case DIK_ABNT_C1: case DIK_ABNT_C2: case DIK_PREVTRACK: case DIK_PLAYPAUSE: case DIK_NEXTTRACK: case DIK_MUTE: case DIK_CALCULATOR: case DIK_MEDIASTOP: case DIK_VOLUMEDOWN: case DIK_VOLUMEUP: case DIK_WEBHOME: case DIK_WAKE: case DIK_WEBSEARCH: case DIK_WEBFAVORITES: case DIK_WEBREFRESH: case DIK_WEBSTOP: case DIK_WEBFORWARD: case DIK_WEBBACK: case DIK_MYCOMPUTER: case DIK_MAIL: case DIK_MEDIASELECT: case DIK_OEM_102: default: return Component.Identifier.Key.UNKNOWN; } } public final static Component.Identifier.Button getButtonIdentifier(int id) { switch (id) { case 0: return Component.Identifier.Button._0; case 1: return Component.Identifier.Button._1; case 2: return Component.Identifier.Button._2; case 3: return Component.Identifier.Button._3; case 4: return Component.Identifier.Button._4; case 5: return Component.Identifier.Button._5; case 6: return Component.Identifier.Button._6; case 7: return Component.Identifier.Button._7; case 8: return Component.Identifier.Button._8; case 9: return Component.Identifier.Button._9; case 10: return Component.Identifier.Button._10; case 11: return Component.Identifier.Button._11; case 12: return Component.Identifier.Button._12; case 13: return Component.Identifier.Button._13; case 14: return Component.Identifier.Button._14; case 15: return Component.Identifier.Button._15; case 16: return Component.Identifier.Button._16; case 17: return Component.Identifier.Button._17; case 18: return Component.Identifier.Button._18; case 19: return Component.Identifier.Button._19; case 20: return Component.Identifier.Button._20; case 21: return Component.Identifier.Button._21; case 22: return Component.Identifier.Button._23; case 23: return Component.Identifier.Button._24; case 24: return Component.Identifier.Button._25; case 25: return Component.Identifier.Button._26; case 26: return Component.Identifier.Button._27; case 27: return Component.Identifier.Button._28; case 28: return Component.Identifier.Button._29; case 29: return Component.Identifier.Button._30; case 30: return Component.Identifier.Button._31; default: return null; } } public final static Component.Identifier.Button mapMouseButtonIdentifier(Component.Identifier.Button button_id) { if (button_id == Component.Identifier.Button._0) { return Component.Identifier.Button.LEFT; } else if (button_id == Component.Identifier.Button._1) { return Component.Identifier.Button.RIGHT; } else if (button_id == Component.Identifier.Button._2) { return Component.Identifier.Button.MIDDLE; } else return button_id; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DirectInputEnvironmentPlugin.java0000644000175000017500000002210711164715231032545 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.List; import java.util.ArrayList; import java.io.File; import java.io.IOException; import net.java.games.util.plugins.Plugin; /** DirectInput implementation of controller environment * @author martak * @author elias * @version 1.0 */ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment implements Plugin { private static boolean supported = false; /** * Static utility method for loading native libraries. * It will try to load from either the path given by * the net.java.games.input.librarypath property * or through System.loadLibrary(). * */ static void loadLibrary(final String lib_name) { AccessController.doPrivileged( new PrivilegedAction() { public final Object run() { try { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); else System.loadLibrary(lib_name); } catch (UnsatisfiedLinkError e) { e.printStackTrace(); supported = false; } return null; } }); } static String getPrivilegedProperty(final String property) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property); } }); } static String getPrivilegedProperty(final String property, final String default_value) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property, default_value); } }); } static { String osName = getPrivilegedProperty("os.name", "").trim(); if(osName.startsWith("Windows")) { supported = true; if("x86".equals(getPrivilegedProperty("os.arch"))) { loadLibrary("jinput-dx8"); } else { loadLibrary("jinput-dx8_64"); } } } private final Controller[] controllers; private final List active_devices = new ArrayList(); private final DummyWindow window; /** Creates new DirectInputEnvironment */ public DirectInputEnvironmentPlugin() { DummyWindow window = null; Controller[] controllers = new Controller[]{}; if(isSupported()) { try { window = new DummyWindow(); try { controllers = enumControllers(window); } catch (IOException e) { window.destroy(); throw e; } } catch (IOException e) { logln("Failed to enumerate devices: " + e.getMessage()); } this.window = window; this.controllers = controllers; AccessController.doPrivileged( new PrivilegedAction() { public final Object run() { Runtime.getRuntime().addShutdownHook(new ShutdownHook()); return null; } }); } else { // These are final fields, so can't set them, then over ride // them if we are supported. this.window = null; this.controllers = controllers; } } public final Controller[] getControllers() { return controllers; } private final Component[] createComponents(IDirectInputDevice device, boolean map_mouse_buttons) { List device_objects = device.getObjects(); List controller_components = new ArrayList(); for (int i = 0; i < device_objects.size(); i++) { DIDeviceObject device_object = (DIDeviceObject)device_objects.get(i); Component.Identifier identifier = device_object.getIdentifier(); if (identifier == null) continue; if (map_mouse_buttons && identifier instanceof Component.Identifier.Button) { identifier = DIIdentifierMap.mapMouseButtonIdentifier((Component.Identifier.Button)identifier); } DIComponent component = new DIComponent(identifier, device_object); controller_components.add(component); device.registerComponent(device_object, component); } Component[] components = new Component[controller_components.size()]; controller_components.toArray(components); return components; } private final Mouse createMouseFromDevice(IDirectInputDevice device) { Component[] components = createComponents(device, true); Mouse mouse = new DIMouse(device, components, new Controller[]{}, device.getRumblers()); if (mouse.getX() != null && mouse.getY() != null && mouse.getPrimaryButton() != null) return mouse; else return null; } private final AbstractController createControllerFromDevice(IDirectInputDevice device, Controller.Type type) { Component[] components = createComponents(device, false); AbstractController controller = new DIAbstractController(device, components, new Controller[]{}, device.getRumblers(), type); return controller; } private final Keyboard createKeyboardFromDevice(IDirectInputDevice device) { Component[] components = createComponents(device, false); return new DIKeyboard(device, components, new Controller[]{}, device.getRumblers()); } private final Controller createControllerFromDevice(IDirectInputDevice device) { switch (device.getType()) { case IDirectInputDevice.DI8DEVTYPE_MOUSE: return createMouseFromDevice(device); case IDirectInputDevice.DI8DEVTYPE_KEYBOARD: return createKeyboardFromDevice(device); case IDirectInputDevice.DI8DEVTYPE_GAMEPAD: return createControllerFromDevice(device, Controller.Type.GAMEPAD); case IDirectInputDevice.DI8DEVTYPE_DRIVING: return createControllerFromDevice(device, Controller.Type.WHEEL); case IDirectInputDevice.DI8DEVTYPE_1STPERSON: /* Fall through */ case IDirectInputDevice.DI8DEVTYPE_FLIGHT: /* Fall through */ case IDirectInputDevice.DI8DEVTYPE_JOYSTICK: return createControllerFromDevice(device, Controller.Type.STICK); default: return createControllerFromDevice(device, Controller.Type.UNKNOWN); } } private final Controller[] enumControllers(DummyWindow window) throws IOException { List controllers = new ArrayList(); IDirectInput dinput = new IDirectInput(window); try { List devices = dinput.getDevices(); for (int i = 0; i < devices.size(); i++) { IDirectInputDevice device = (IDirectInputDevice)devices.get(i); Controller controller = createControllerFromDevice(device); if (controller != null) { controllers.add(controller); active_devices.add(device); } else device.release(); } } finally { dinput.release(); } Controller[] controllers_array = new Controller[controllers.size()]; controllers.toArray(controllers_array); return controllers_array; } private final class ShutdownHook extends Thread { public final void run() { /* Release the devices to kill off active force feedback effects */ for (int i = 0; i < active_devices.size(); i++) { IDirectInputDevice device = (IDirectInputDevice)active_devices.get(i); device.release(); } /* We won't release the window since it is * owned by the thread that created the environment. */ } } public boolean isSupported() { return supported; } } // class DirectInputEnvironment jinput-20100502/plugins/windows/src/java/net/java/games/input/SetupAPIDevice.java0000644000175000017500000000506110424764301027461 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper of a SetupAPI device * @author elias * @version 1.0 */ final class SetupAPIDevice { private final String device_instance_id; private final String device_name; public SetupAPIDevice(String device_instance_id, String device_name) { this.device_instance_id = device_instance_id; this.device_name = device_name; } public final String getName() { return device_name; } public final String getInstanceId() { return device_instance_id; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawMouseInfo.java0000644000175000017500000000710010424764301027261 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper of RID_DEVICE_INFO_MOUSE * @author elias * @version 1.0 */ class RawMouseInfo extends RawDeviceInfo { private final RawDevice device; private final int id; private final int num_buttons; private final int sample_rate; public RawMouseInfo(RawDevice device, int id, int num_buttons, int sample_rate) { this.device = device; this.id = id; this.num_buttons = num_buttons; this.sample_rate = sample_rate; } public final int getUsage() { return 2; } public final int getUsagePage() { return 1; } public final long getHandle() { return device.getHandle(); } public final Controller createControllerFromDevice(RawDevice device, SetupAPIDevice setupapi_device) throws IOException { if (num_buttons == 0) return null; // A raw mouse contains the x and y and z axis and the buttons Component[] components = new Component[3 + num_buttons]; int index = 0; components[index++] = new RawMouse.Axis(device, Component.Identifier.Axis.X); components[index++] = new RawMouse.Axis(device, Component.Identifier.Axis.Y); components[index++] = new RawMouse.Axis(device, Component.Identifier.Axis.Z); for (int i = 0; i < num_buttons; i++) { Component.Identifier.Button id = DIIdentifierMap.mapMouseButtonIdentifier(DIIdentifierMap.getButtonIdentifier(i)); components[index++] = new RawMouse.Button(device, id, i); } Controller mouse = new RawMouse(setupapi_device.getName(), device, components, new Controller[]{}, new Rumbler[]{}); return mouse; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DIKeyboard.java0000644000175000017500000000532210424764275026676 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** * @author elias * @version 1.0 */ final class DIKeyboard extends Keyboard { private final IDirectInputDevice device; protected DIKeyboard(IDirectInputDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) { super(device.getProductName(), components, children, rumblers); this.device = device; } protected final boolean getNextDeviceEvent(Event event) throws IOException { return DIControllers.getNextDeviceEvent(event, device); } public final void pollDevice() throws IOException { device.pollAll(); } protected final void setDeviceEventQueueSize(int size) throws IOException { device.setBufferSize(size); } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DataQueue.java0000644000175000017500000000711010424764275026574 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * @author elias * @version 1.0 */ final class DataQueue { private final Object[] elements; private int position; private int limit; public DataQueue(int size, Class element_type) { this.elements= new Object[size]; for (int i = 0; i < elements.length; i++) { try { elements[i] = element_type.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } clear(); } public final void clear() { position = 0; limit = elements.length; } public final int position() { return position; } public final int limit() { return limit; } public final Object get(int index) { assert index < limit; return elements[index]; } public final Object get() { if (!hasRemaining()) return null; return get(position++); } public final void compact() { int index = 0; while (hasRemaining()) { swap(position, index); position++; index++; } position = index; limit = elements.length; } private final void swap(int index1, int index2) { Object temp = elements[index1]; elements[index1] = elements[index2]; elements[index2] = temp; } public final void flip() { limit = position; position = 0; } public final boolean hasRemaining() { return remaining() > 0; } public final int remaining() { return limit - position; } public final void position(int position) { this.position = position; } public final Object[] getElements() { return elements; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/IDirectInput.java0000644000175000017500000000751010633011277027252 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; import java.util.List; import java.util.ArrayList; /** Java wrapper for IDirectInput * @author martak * @author elias * @version 1.0 */ final class IDirectInput { private final List devices = new ArrayList(); private final long idirectinput_address; private final DummyWindow window; public IDirectInput(DummyWindow window) throws IOException { this.window = window; this.idirectinput_address = createIDirectInput(); try { enumDevices(); } catch (IOException e) { releaseDevices(); release(); throw e; } } private final static native long createIDirectInput() throws IOException; public final List getDevices() { return devices; } private final void enumDevices() throws IOException { nEnumDevices(idirectinput_address); } private final native void nEnumDevices(long addr) throws IOException; /* This method is called from native code in nEnumDevices * native side will clean up in case of an exception */ private final void addDevice(long address, byte[] instance_guid, byte[] product_guid, int dev_type, int dev_subtype, String instance_name, String product_name) throws IOException { try { IDirectInputDevice device = new IDirectInputDevice(window, address, instance_guid, product_guid, dev_type, dev_subtype, instance_name, product_name); devices.add(device); } catch (IOException e) { DirectInputEnvironmentPlugin.logln("Failed to initialize device " + product_name + " because of: " + e); } } public final void releaseDevices() { for (int i = 0; i < devices.size(); i++) { IDirectInputDevice device = (IDirectInputDevice)devices.get(i); device.release(); } } public final void release() { nRelease(idirectinput_address); } private final static native void nRelease(long address); } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawKeyboardInfo.java0000644000175000017500000000631310424764300027735 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper of RID_DEVICE_INFO_KEYBOARD * @author elias * @version 1.0 */ class RawKeyboardInfo extends RawDeviceInfo { private final RawDevice device; private final int type; private final int sub_type; private final int keyboard_mode; private final int num_function_keys; private final int num_indicators; private final int num_keys_total; public RawKeyboardInfo(RawDevice device, int type, int sub_type, int keyboard_mode, int num_function_keys, int num_indicators, int num_keys_total) { this.device = device; this.type = type; this.sub_type = sub_type; this.keyboard_mode = keyboard_mode; this.num_function_keys = num_function_keys; this.num_indicators = num_indicators; this.num_keys_total = num_keys_total; } public final int getUsage() { return 6; } public final int getUsagePage() { return 1; } public final long getHandle() { return device.getHandle(); } public final Controller createControllerFromDevice(RawDevice device, SetupAPIDevice setupapi_device) throws IOException { return new RawKeyboard(setupapi_device.getName(), device, new Controller[]{}, new Rumbler[]{}); } } jinput-20100502/plugins/windows/src/java/net/java/games/input/DIControllers.java0000644000175000017500000000624110466564272027446 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** * @author elias * @version 1.0 */ final class DIControllers { private final static DIDeviceObjectData di_event = new DIDeviceObjectData(); /* synchronized to protect di_event */ public final static synchronized boolean getNextDeviceEvent(Event event, IDirectInputDevice device) throws IOException { if (!device.getNextEvent(di_event)) return false; DIDeviceObject object = device.mapEvent(di_event); DIComponent component = device.mapObject(object); if (component == null) return false; int event_value; if (object.isRelative()) { event_value = object.getRelativeEventValue(di_event.getData()); } else { event_value = di_event.getData(); } event.set(component, component.getDeviceObject().convertValue(event_value), di_event.getNanos()); return true; } public final static float poll(Component component, DIDeviceObject object) throws IOException { int poll_data = object.getDevice().getPollData(object); float result; if (object.isRelative()) { result = object.getRelativePollValue(poll_data); } else { result = poll_data; } return object.convertValue(result); } } jinput-20100502/plugins/windows/src/java/net/java/games/input/IDirectInputDevice.java0000644000175000017500000005314010633011277030372 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; import java.util.Arrays; /** Java wrapper for IDirectInputDevice * @author martak * @author elias * @version 1.0 */ final class IDirectInputDevice { public final static int GUID_XAxis = 1; public final static int GUID_YAxis = 2; public final static int GUID_ZAxis = 3; public final static int GUID_RxAxis = 4; public final static int GUID_RyAxis = 5; public final static int GUID_RzAxis = 6; public final static int GUID_Slider = 7; public final static int GUID_Button = 8; public final static int GUID_Key = 9; public final static int GUID_POV = 10; public final static int GUID_Unknown = 11; public final static int GUID_ConstantForce = 12; public final static int GUID_RampForce = 13; public final static int GUID_Square = 14; public final static int GUID_Sine = 15; public final static int GUID_Triangle = 16; public final static int GUID_SawtoothUp = 17; public final static int GUID_SawtoothDown = 18; public final static int GUID_Spring = 19; public final static int GUID_Damper = 20; public final static int GUID_Inertia = 21; public final static int GUID_Friction = 22; public final static int GUID_CustomForce = 23; public final static int DI8DEVTYPE_DEVICE = 0x11; public final static int DI8DEVTYPE_MOUSE = 0x12; public final static int DI8DEVTYPE_KEYBOARD = 0x13; public final static int DI8DEVTYPE_JOYSTICK = 0x14; public final static int DI8DEVTYPE_GAMEPAD = 0x15; public final static int DI8DEVTYPE_DRIVING = 0x16; public final static int DI8DEVTYPE_FLIGHT = 0x17; public final static int DI8DEVTYPE_1STPERSON = 0x18; public final static int DI8DEVTYPE_DEVICECTRL = 0x19; public final static int DI8DEVTYPE_SCREENPOINTER = 0x1A; public final static int DI8DEVTYPE_REMOTE = 0x1B; public final static int DI8DEVTYPE_SUPPLEMENTAL = 0x1C; public final static int DISCL_EXCLUSIVE = 0x00000001; public final static int DISCL_NONEXCLUSIVE = 0x00000002; public final static int DISCL_FOREGROUND = 0x00000004; public final static int DISCL_BACKGROUND = 0x00000008; public final static int DISCL_NOWINKEY = 0x00000010; public final static int DIDFT_ALL = 0x00000000; public final static int DIDFT_RELAXIS = 0x00000001; public final static int DIDFT_ABSAXIS = 0x00000002; public final static int DIDFT_AXIS = 0x00000003; public final static int DIDFT_PSHBUTTON = 0x00000004; public final static int DIDFT_TGLBUTTON = 0x00000008; public final static int DIDFT_BUTTON = 0x0000000C; public final static int DIDFT_POV = 0x00000010; public final static int DIDFT_COLLECTION = 0x00000040; public final static int DIDFT_NODATA = 0x00000080; public final static int DIDFT_FFACTUATOR = 0x01000000; public final static int DIDFT_FFEFFECTTRIGGER = 0x02000000; public final static int DIDFT_OUTPUT = 0x10000000; public final static int DIDFT_VENDORDEFINED = 0x04000000; public final static int DIDFT_ALIAS = 0x08000000; public final static int DIDFT_OPTIONAL = 0x80000000; public final static int DIDFT_NOCOLLECTION = 0x00FFFF00; public final static int DIDF_ABSAXIS = 0x00000001; public final static int DIDF_RELAXIS = 0x00000002; public final static int DI_OK = 0x00000000; public final static int DI_NOEFFECT = 0x00000001; public final static int DI_PROPNOEFFECT = 0x00000001; public final static int DI_POLLEDDEVICE = 0x00000002; public final static int DI_DOWNLOADSKIPPED = 0x00000003; public final static int DI_EFFECTRESTARTED = 0x00000004; public final static int DI_TRUNCATED = 0x00000008; public final static int DI_SETTINGSNOTSAVED = 0x0000000B; public final static int DI_TRUNCATEDANDRESTARTED = 0x0000000C; public final static int DI_BUFFEROVERFLOW = 0x00000001; public final static int DIERR_INPUTLOST = 0x8007001E; public final static int DIERR_NOTACQUIRED = 0x8007001C; public final static int DIERR_OTHERAPPHASPRIO = 0x80070005; public final static int DIDOI_FFACTUATOR = 0x00000001; public final static int DIDOI_FFEFFECTTRIGGER = 0x00000002; public final static int DIDOI_POLLED = 0x00008000; public final static int DIDOI_ASPECTPOSITION = 0x00000100; public final static int DIDOI_ASPECTVELOCITY = 0x00000200; public final static int DIDOI_ASPECTACCEL = 0x00000300; public final static int DIDOI_ASPECTFORCE = 0x00000400; public final static int DIDOI_ASPECTMASK = 0x00000F00; public final static int DIDOI_GUIDISUSAGE = 0x00010000; public final static int DIEFT_ALL = 0x00000000; public final static int DIEFT_CONSTANTFORCE = 0x00000001; public final static int DIEFT_RAMPFORCE = 0x00000002; public final static int DIEFT_PERIODIC = 0x00000003; public final static int DIEFT_CONDITION = 0x00000004; public final static int DIEFT_CUSTOMFORCE = 0x00000005; public final static int DIEFT_HARDWARE = 0x000000FF; public final static int DIEFT_FFATTACK = 0x00000200; public final static int DIEFT_FFFADE = 0x00000400; public final static int DIEFT_SATURATION = 0x00000800; public final static int DIEFT_POSNEGCOEFFICIENTS = 0x00001000; public final static int DIEFT_POSNEGSATURATION = 0x00002000; public final static int DIEFT_DEADBAND = 0x00004000; public final static int DIEFT_STARTDELAY = 0x00008000; public final static int DIEFF_OBJECTIDS = 0x00000001; public final static int DIEFF_OBJECTOFFSETS = 0x00000002; public final static int DIEFF_CARTESIAN = 0x00000010; public final static int DIEFF_POLAR = 0x00000020; public final static int DIEFF_SPHERICAL = 0x00000040; public final static int DIEP_DURATION = 0x00000001; public final static int DIEP_SAMPLEPERIOD = 0x00000002; public final static int DIEP_GAIN = 0x00000004; public final static int DIEP_TRIGGERBUTTON = 0x00000008; public final static int DIEP_TRIGGERREPEATINTERVAL = 0x00000010; public final static int DIEP_AXES = 0x00000020; public final static int DIEP_DIRECTION = 0x00000040; public final static int DIEP_ENVELOPE = 0x00000080; public final static int DIEP_TYPESPECIFICPARAMS = 0x00000100; public final static int DIEP_STARTDELAY = 0x00000200; public final static int DIEP_ALLPARAMS_DX5 = 0x000001FF; public final static int DIEP_ALLPARAMS = 0x000003FF; public final static int DIEP_START = 0x20000000; public final static int DIEP_NORESTART = 0x40000000; public final static int DIEP_NODOWNLOAD = 0x80000000; public final static int DIEB_NOTRIGGER = 0xFFFFFFFF; public final static int INFINITE = 0xFFFFFFFF; public final static int DI_DEGREES = 100; public final static int DI_FFNOMINALMAX = 10000; public final static int DI_SECONDS = 1000000; public final static int DIPROPRANGE_NOMIN = 0x80000000; public final static int DIPROPRANGE_NOMAX = 0x7FFFFFFF; private final DummyWindow window; private final long address; private final int dev_type; private final int dev_subtype; private final String instance_name; private final String product_name; private final List objects = new ArrayList(); private final List effects = new ArrayList(); private final List rumblers = new ArrayList(); private final int[] device_state; private final Map object_to_component = new HashMap(); private final boolean axes_in_relative_mode; private boolean released; private DataQueue queue; private int button_counter; private int current_format_offset; public IDirectInputDevice(DummyWindow window, long address, byte[] instance_guid, byte[] product_guid, int dev_type, int dev_subtype, String instance_name, String product_name) throws IOException { this.window = window; this.address = address; this.product_name = product_name; this.instance_name = instance_name; this.dev_type = dev_type; this.dev_subtype = dev_subtype; // Assume that the caller (native side) releases the device if setup fails enumObjects(); try { enumEffects(); createRumblers(); } catch (IOException e) { DirectInputEnvironmentPlugin.logln("Failed to create rumblers: " + e.getMessage()); } /* Some DirectInput lamer-designer made the device state * axis mode be per-device not per-axis, so I'll just * get all axes as absolute and compensate for relative axes. * * Unless, of course, all axes are relative like a mouse device, * in which case setting the DIDF_ABSAXIS flag will result in * incorrect axis values returned from GetDeviceData for some * obscure reason. */ boolean all_relative = true; boolean has_axis = false; for (int i = 0; i < objects.size(); i++) { DIDeviceObject obj = (DIDeviceObject)objects.get(i); if (obj.isAxis()) { has_axis = true; if (!obj.isRelative()) { all_relative = false; break; } } } this.axes_in_relative_mode = all_relative && has_axis; int axis_mode = all_relative ? DIDF_RELAXIS : DIDF_ABSAXIS; setDataFormat(axis_mode); if (rumblers.size() > 0) { try { setCooperativeLevel(DISCL_BACKGROUND | DISCL_EXCLUSIVE); } catch (IOException e) { setCooperativeLevel(DISCL_BACKGROUND | DISCL_NONEXCLUSIVE); } } else setCooperativeLevel(DISCL_BACKGROUND | DISCL_NONEXCLUSIVE); setBufferSize(AbstractController.EVENT_QUEUE_DEPTH); acquire(); this.device_state = new int[objects.size()]; } public final boolean areAxesRelative() { return axes_in_relative_mode; } public final Rumbler[] getRumblers() { return (Rumbler[])rumblers.toArray(new Rumbler[]{}); } private final List createRumblers() throws IOException { DIDeviceObject x_axis = lookupObjectByGUID(GUID_XAxis); // DIDeviceObject y_axis = lookupObjectByGUID(GUID_YAxis); if(x_axis == null/* || y_axis == null*/) return rumblers; DIDeviceObject[] axes = {x_axis/*, y_axis*/}; long[] directions = {0/*, 0*/}; for (int i = 0; i < effects.size(); i++) { DIEffectInfo info = (DIEffectInfo)effects.get(i); if ((info.getEffectType() & 0xff) == DIEFT_PERIODIC && (info.getDynamicParams() & DIEP_GAIN) != 0) { rumblers.add(createPeriodicRumbler(axes, directions, info)); } } return rumblers; } private final Rumbler createPeriodicRumbler(DIDeviceObject[] axes, long[] directions, DIEffectInfo info) throws IOException { int[] axis_ids = new int[axes.length]; for (int i = 0; i < axis_ids.length; i++) { axis_ids[i] = axes[i].getDIIdentifier(); } long effect_address = nCreatePeriodicEffect(address, info.getGUID(), DIEFF_CARTESIAN | DIEFF_OBJECTIDS, INFINITE, 0, DI_FFNOMINALMAX, DIEB_NOTRIGGER, 0, axis_ids, directions, 0, 0, 0, 0, DI_FFNOMINALMAX, 0, 0, 50000, 0); return new IDirectInputEffect(effect_address, info); } private final static native long nCreatePeriodicEffect(long address, byte[] effect_guid, int flags, int duration, int sample_period, int gain, int trigger_button, int trigger_repeat_interval, int[] axis_ids, long[] directions, int envelope_attack_level, int envelope_attack_time, int envelope_fade_level, int envelope_fade_time, int periodic_magnitude, int periodic_offset, int periodic_phase, int periodic_period, int start_delay) throws IOException; private final DIDeviceObject lookupObjectByGUID(int guid_id) { for (int i = 0; i < objects.size(); i++) { DIDeviceObject object = (DIDeviceObject)objects.get(i); if (guid_id == object.getGUIDType()) return object; } return null; } public final int getPollData(DIDeviceObject object) { return device_state[object.getFormatOffset()]; } public final DIDeviceObject mapEvent(DIDeviceObjectData event) { /* Raw event format offsets (dwOfs member) is in bytes, * but we're indexing into ints so we have to compensate * for the int size (4 bytes) */ int format_offset = event.getFormatOffset()/4; return (DIDeviceObject)objects.get(format_offset); } public final DIComponent mapObject(DIDeviceObject object) { return (DIComponent)object_to_component.get(object); } public final void registerComponent(DIDeviceObject object, DIComponent component) { object_to_component.put(object, component); } public final synchronized void pollAll() throws IOException { checkReleased(); poll(); getDeviceState(device_state); queue.compact(); getDeviceData(queue); queue.flip(); } public synchronized final boolean getNextEvent(DIDeviceObjectData data) { DIDeviceObjectData next_event = (DIDeviceObjectData)queue.get(); if (next_event == null) return false; data.set(next_event); return true; } private final void poll() throws IOException { int res = nPoll(address); if (res != DI_OK && res != DI_NOEFFECT) { if (res == DIERR_NOTACQUIRED) { acquire(); return; } throw new IOException("Failed to poll device (" + Integer.toHexString(res) + ")"); } } private final static native int nPoll(long address) throws IOException; private final void acquire() throws IOException { int res = nAcquire(address); if (res != DI_OK && res != DIERR_OTHERAPPHASPRIO && res != DI_NOEFFECT) throw new IOException("Failed to acquire device (" + Integer.toHexString(res) + ")"); } private final static native int nAcquire(long address); private final void unacquire() throws IOException { int res = nUnacquire(address); if (res != DI_OK && res != DI_NOEFFECT) throw new IOException("Failed to unAcquire device (" + Integer.toHexString(res) + ")"); } private final static native int nUnacquire(long address); private final boolean getDeviceData(DataQueue queue) throws IOException { int res = nGetDeviceData(address, 0, queue, queue.getElements(), queue.position(), queue.remaining()); if (res != DI_OK && res != DI_BUFFEROVERFLOW) { if (res == DIERR_NOTACQUIRED) { acquire(); return false; } throw new IOException("Failed to get device data (" + Integer.toHexString(res) + ")"); } return true; } private final static native int nGetDeviceData(long address, int flags, DataQueue queue, Object[] queue_elements, int position, int remaining); private final void getDeviceState(int[] device_state) throws IOException { int res = nGetDeviceState(address, device_state); if (res != DI_OK) { if (res == DIERR_NOTACQUIRED) { Arrays.fill(device_state, 0); acquire(); return; } throw new IOException("Failed to get device state (" + Integer.toHexString(res) + ")"); } } private final static native int nGetDeviceState(long address, int[] device_state); /* Set a custom data format that maps each object's data into an int[] array with the same index as in the objects List */ private final void setDataFormat(int flags) throws IOException { DIDeviceObject[] device_objects = new DIDeviceObject[objects.size()]; objects.toArray(device_objects); int res = nSetDataFormat(address, flags, device_objects); if (res != DI_OK) throw new IOException("Failed to set data format (" + Integer.toHexString(res) + ")"); } private final static native int nSetDataFormat(long address, int flags, DIDeviceObject[] device_objects); public final String getProductName() { return product_name; } public final int getType() { return dev_type; } public final List getObjects() { return objects; } private final void enumEffects() throws IOException { int res = nEnumEffects(address, DIEFT_ALL); if (res != DI_OK) throw new IOException("Failed to enumerate effects (" + Integer.toHexString(res) + ")"); } private final native int nEnumEffects(long address, int flags); /* Called from native side from nEnumEffects */ private final void addEffect(byte[] guid, int guid_id, int effect_type, int static_params, int dynamic_params, String name) { effects.add(new DIEffectInfo(this, guid, guid_id, effect_type, static_params, dynamic_params, name)); } private final void enumObjects() throws IOException { int res = nEnumObjects(address, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); if (res != DI_OK) throw new IOException("Failed to enumerate objects (" + Integer.toHexString(res) + ")"); } private final native int nEnumObjects(long address, int flags); public final synchronized long[] getRangeProperty(int object_identifier) throws IOException { checkReleased(); long[] range = new long[2]; int res = nGetRangeProperty(address, object_identifier, range); if (res != DI_OK) throw new IOException("Failed to get object range (" + res + ")"); return range; } private final static native int nGetRangeProperty(long address, int object_id, long[] range); public final synchronized int getDeadzoneProperty(int object_identifier) throws IOException { checkReleased(); return nGetDeadzoneProperty(address, object_identifier); } private final static native int nGetDeadzoneProperty(long address, int object_id) throws IOException; /* Called from native side from nEnumObjects */ private final void addObject(byte[] guid, int guid_type, int identifier, int type, int instance, int flags, String name) throws IOException { Component.Identifier id = getIdentifier(guid_type, type, instance); int format_offset = current_format_offset++; DIDeviceObject obj = new DIDeviceObject(this, id, guid, guid_type, identifier, type, instance, flags, name, format_offset); objects.add(obj); } private final static Component.Identifier.Key getKeyIdentifier(int key_instance) { return DIIdentifierMap.getKeyIdentifier(key_instance); } private final Component.Identifier.Button getNextButtonIdentifier() { int button_id = button_counter++; return DIIdentifierMap.getButtonIdentifier(button_id); } private final Component.Identifier getIdentifier(int guid_type, int type, int instance) { switch (guid_type) { case IDirectInputDevice.GUID_XAxis: return Component.Identifier.Axis.X; case IDirectInputDevice.GUID_YAxis: return Component.Identifier.Axis.Y; case IDirectInputDevice.GUID_ZAxis: return Component.Identifier.Axis.Z; case IDirectInputDevice.GUID_RxAxis: return Component.Identifier.Axis.RX; case IDirectInputDevice.GUID_RyAxis: return Component.Identifier.Axis.RY; case IDirectInputDevice.GUID_RzAxis: return Component.Identifier.Axis.RZ; case IDirectInputDevice.GUID_Slider: return Component.Identifier.Axis.SLIDER; case IDirectInputDevice.GUID_POV: return Component.Identifier.Axis.POV; case IDirectInputDevice.GUID_Key: return getKeyIdentifier(instance); case IDirectInputDevice.GUID_Button: return getNextButtonIdentifier(); default: return Component.Identifier.Axis.UNKNOWN; } } public final synchronized void setBufferSize(int size) throws IOException { checkReleased(); unacquire(); int res = nSetBufferSize(address, size); if (res != DI_OK && res != DI_PROPNOEFFECT && res != DI_POLLEDDEVICE) throw new IOException("Failed to set buffer size (" + Integer.toHexString(res) + ")"); queue = new DataQueue(size, DIDeviceObjectData.class); queue.position(queue.limit()); acquire(); } private final static native int nSetBufferSize(long address, int size); public final synchronized void setCooperativeLevel(int flags) throws IOException { checkReleased(); int res = nSetCooperativeLevel(address, window.getHwnd(), flags); if (res != DI_OK) throw new IOException("Failed to set cooperative level (" + Integer.toHexString(res) + ")"); } private final static native int nSetCooperativeLevel(long address, long hwnd_address, int flags); public synchronized final void release() { if (!released) { released = true; for (int i = 0; i < rumblers.size(); i++) { IDirectInputEffect effect = (IDirectInputEffect)rumblers.get(i); effect.release(); } nRelease(address); } } private final static native void nRelease(long address); private final void checkReleased() throws IOException { if (released) throw new IOException("Device is released"); } protected void finalize() { release(); } } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawKeyboardEvent.java0000644000175000017500000000565010424764300030126 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper of RAWKEYBOARD * @author elias * @version 1.0 */ final class RawKeyboardEvent { private long millis; private int make_code; private int flags; private int vkey; private int message; private long extra_information; public final void set(long millis, int make_code, int flags, int vkey, int message, long extra_information) { this.millis = millis; this.make_code = make_code; this.flags = flags; this.vkey = vkey; this.message = message; this.extra_information = extra_information; } public final void set(RawKeyboardEvent event) { set(event.millis, event.make_code, event.flags, event.vkey, event.message, event.extra_information); } public final int getVKey() { return vkey; } public final int getMessage() { return message; } public final long getNanos() { return millis*1000000L; } } jinput-20100502/plugins/windows/src/java/net/java/games/input/IDirectInputEffect.java0000644000175000017500000001047010633011277030366 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Java wrapper for IDirectInputEffect * @author elias * @version 1.0 */ final class IDirectInputEffect implements Rumbler { private final long address; private final DIEffectInfo info; private boolean released; public IDirectInputEffect(long address, DIEffectInfo info) { this.address = address; this.info = info; } public final synchronized void rumble(float intensity) { try { checkReleased(); if (intensity > 0) { int int_gain = (int)Math.round(intensity*IDirectInputDevice.DI_FFNOMINALMAX); setGain(int_gain); start(1, 0); } else stop(); } catch (IOException e) { DirectInputEnvironmentPlugin.logln("Failed to set rumbler gain: " + e.getMessage()); } } public final Component.Identifier getAxisIdentifier() { return null; } public final String getAxisName() { return null; } public final synchronized void release() { if (!released) { released = true; nRelease(address); } } private final static native void nRelease(long address); private final void checkReleased() throws IOException { if (released) throw new IOException(); } private final void setGain(int gain) throws IOException { int res = nSetGain(address, gain); if (res != IDirectInputDevice.DI_DOWNLOADSKIPPED && res != IDirectInputDevice.DI_EFFECTRESTARTED && res != IDirectInputDevice.DI_OK && res != IDirectInputDevice.DI_TRUNCATED && res != IDirectInputDevice.DI_TRUNCATEDANDRESTARTED) { throw new IOException("Failed to set effect gain (0x" + Integer.toHexString(res) + ")"); } } private final static native int nSetGain(long address, int gain); private final void start(int iterations, int flags) throws IOException { int res = nStart(address, iterations, flags); if (res != IDirectInputDevice.DI_OK) throw new IOException("Failed to start effect (0x" + Integer.toHexString(res) + ")"); } private final static native int nStart(long address, int iterations, int flags); private final void stop() throws IOException { int res = nStop(address); if (res != IDirectInputDevice.DI_OK) throw new IOException("Failed to stop effect (0x" + Integer.toHexString(res) + ")"); } private final static native int nStop(long address); protected void finalize() { release(); } } jinput-20100502/plugins/windows/src/java/net/java/games/input/RawIdentifierMap.java0000644000175000017500000004674410424764277030132 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** * @author elias * @version 1.0 */ final class RawIdentifierMap { public final static int VK_LBUTTON = 0x01; public final static int VK_RBUTTON = 0x02; public final static int VK_CANCEL = 0x03; public final static int VK_MBUTTON = 0x04; /* NOT contiguous with L & RBUTTON */ public final static int VK_XBUTTON1 = 0x05; /* NOT contiguous with L & RBUTTON */ public final static int VK_XBUTTON2 = 0x06; /* NOT contiguous with L & RBUTTON */ /* * 0x07 : unassigned */ public final static int VK_BACK = 0x08; public final static int VK_TAB = 0x09; /* * 0x0A - 0x0B : reserved */ public final static int VK_CLEAR = 0x0C; public final static int VK_RETURN = 0x0D; public final static int VK_SHIFT = 0x10; public final static int VK_CONTROL = 0x11; public final static int VK_MENU = 0x12; public final static int VK_PAUSE = 0x13; public final static int VK_CAPITAL = 0x14; public final static int VK_KANA = 0x15; public final static int VK_HANGEUL = 0x15; /* old name - should be here for compatibility */ public final static int VK_HANGUL = 0x15; public final static int VK_JUNJA = 0x17; public final static int VK_FINAL = 0x18; public final static int VK_HANJA = 0x19; public final static int VK_KANJI = 0x19; public final static int VK_ESCAPE = 0x1B; public final static int VK_CONVERT = 0x1C; public final static int VK_NONCONVERT = 0x1D; public final static int VK_ACCEPT = 0x1E; public final static int VK_MODECHANGE = 0x1F; public final static int VK_SPACE = 0x20; public final static int VK_PRIOR = 0x21; public final static int VK_NEXT = 0x22; public final static int VK_END = 0x23; public final static int VK_HOME = 0x24; public final static int VK_LEFT = 0x25; public final static int VK_UP = 0x26; public final static int VK_RIGHT = 0x27; public final static int VK_DOWN = 0x28; public final static int VK_SELECT = 0x29; public final static int VK_PRINT = 0x2A; public final static int VK_EXECUTE = 0x2B; public final static int VK_SNAPSHOT = 0x2C; public final static int VK_INSERT = 0x2D; public final static int VK_DELETE = 0x2E; public final static int VK_HELP = 0x2F; /* * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39) * 0x40 : unassigned * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) */ public final static int VK_0 = 0x30; public final static int VK_1 = 0x31; public final static int VK_2 = 0x32; public final static int VK_3 = 0x33; public final static int VK_4 = 0x34; public final static int VK_5 = 0x35; public final static int VK_6 = 0x36; public final static int VK_7 = 0x37; public final static int VK_8 = 0x38; public final static int VK_9 = 0x39; public final static int VK_A = 0x41; public final static int VK_B = 0x42; public final static int VK_C = 0x43; public final static int VK_D = 0x44; public final static int VK_E = 0x45; public final static int VK_F = 0x46; public final static int VK_G = 0x47; public final static int VK_H = 0x48; public final static int VK_I = 0x49; public final static int VK_J = 0x4A; public final static int VK_K = 0x4B; public final static int VK_L = 0x4C; public final static int VK_M = 0x4D; public final static int VK_N = 0x4E; public final static int VK_O = 0x4F; public final static int VK_P = 0x50; public final static int VK_Q = 0x51; public final static int VK_R = 0x52; public final static int VK_S = 0x53; public final static int VK_T = 0x54; public final static int VK_U = 0x55; public final static int VK_V = 0x56; public final static int VK_W = 0x57; public final static int VK_X = 0x58; public final static int VK_Y = 0x59; public final static int VK_Z = 0x5A; public final static int VK_LWIN = 0x5B; public final static int VK_RWIN = 0x5C; public final static int VK_APPS = 0x5D; /* * 0x5E : reserved; */ public final static int VK_SLEEP = 0x5F; public final static int VK_NUMPAD0 = 0x60; public final static int VK_NUMPAD1 = 0x61; public final static int VK_NUMPAD2 = 0x62; public final static int VK_NUMPAD3 = 0x63; public final static int VK_NUMPAD4 = 0x64; public final static int VK_NUMPAD5 = 0x65; public final static int VK_NUMPAD6 = 0x66; public final static int VK_NUMPAD7 = 0x67; public final static int VK_NUMPAD8 = 0x68; public final static int VK_NUMPAD9 = 0x69; public final static int VK_MULTIPLY = 0x6A; public final static int VK_ADD = 0x6B; public final static int VK_SEPARATOR = 0x6C; public final static int VK_SUBTRACT = 0x6D; public final static int VK_DECIMAL = 0x6E; public final static int VK_DIVIDE = 0x6F; public final static int VK_F1 = 0x70; public final static int VK_F2 = 0x71; public final static int VK_F3 = 0x72; public final static int VK_F4 = 0x73; public final static int VK_F5 = 0x74; public final static int VK_F6 = 0x75; public final static int VK_F7 = 0x76; public final static int VK_F8 = 0x77; public final static int VK_F9 = 0x78; public final static int VK_F10 = 0x79; public final static int VK_F11 = 0x7A; public final static int VK_F12 = 0x7B; public final static int VK_F13 = 0x7C; public final static int VK_F14 = 0x7D; public final static int VK_F15 = 0x7E; public final static int VK_F16 = 0x7F; public final static int VK_F17 = 0x80; public final static int VK_F18 = 0x81; public final static int VK_F19 = 0x82; public final static int VK_F20 = 0x83; public final static int VK_F21 = 0x84; public final static int VK_F22 = 0x85; public final static int VK_F23 = 0x86; public final static int VK_F24 = 0x87; /* * 0x88 - 0x8F : unassigned; */ public final static int VK_NUMLOCK = 0x90; public final static int VK_SCROLL = 0x91; /* * NEC PC-9800 kbd definitions */ public final static int VK_OEM_NEC_EQUAL = 0x92; // '=' key on numpad /* * Fujitsu/OASYS kbd definitions */ public final static int VK_OEM_FJ_JISHO = 0x92; // 'Dictionary' key public final static int VK_OEM_FJ_MASSHOU = 0x93; // 'Unregister word' key public final static int VK_OEM_FJ_TOUROKU = 0x94; // 'Register word' key public final static int VK_OEM_FJ_LOYA = 0x95; // 'Left OYAYUBI' key public final static int VK_OEM_FJ_ROYA = 0x96; // 'Right OYAYUBI' key /* * 0x97 - 0x9F : unassigned */ /* * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. * Used only as parameters to GetAsyncKeyState() and GetKeyState(). * No other API or message will distinguish left and right keys in this way. */ public final static int VK_LSHIFT = 0xA0; public final static int VK_RSHIFT = 0xA1; public final static int VK_LCONTROL = 0xA2; public final static int VK_RCONTROL = 0xA3; public final static int VK_LMENU = 0xA4; public final static int VK_RMENU = 0xA5; public final static int VK_BROWSER_BACK = 0xA6; public final static int VK_BROWSER_FORWARD = 0xA7; public final static int VK_BROWSER_REFRESH = 0xA8; public final static int VK_BROWSER_STOP = 0xA9; public final static int VK_BROWSER_SEARCH = 0xAA; public final static int VK_BROWSER_FAVORITES = 0xAB; public final static int VK_BROWSER_HOME = 0xAC; public final static int VK_VOLUME_MUTE = 0xAD; public final static int VK_VOLUME_DOWN = 0xAE; public final static int VK_VOLUME_UP = 0xAF; public final static int VK_MEDIA_NEXT_TRACK = 0xB0; public final static int VK_MEDIA_PREV_TRACK = 0xB1; public final static int VK_MEDIA_STOP = 0xB2; public final static int VK_MEDIA_PLAY_PAUSE = 0xB3; public final static int VK_LAUNCH_MAIL = 0xB4; public final static int VK_LAUNCH_MEDIA_SELECT = 0xB5; public final static int VK_LAUNCH_APP1 = 0xB6; public final static int VK_LAUNCH_APP2 = 0xB7; /* * 0xB8 - 0xB9 : reserved */ public final static int VK_OEM_1 = 0xBA; // ';:' for US public final static int VK_OEM_PLUS = 0xBB; // '+' any country public final static int VK_OEM_COMMA = 0xBC; // ',' any country public final static int VK_OEM_MINUS = 0xBD; // '-' any country public final static int VK_OEM_PERIOD = 0xBE; // '.' any country public final static int VK_OEM_2 = 0xBF; // '/?' for US public final static int VK_OEM_3 = 0xC0; // '`~' for US /* * 0xC1 - 0xD7 : reserved */ /* * 0xD8 - 0xDA : unassigned */ public final static int VK_OEM_4 = 0xDB; // '[{' for US public final static int VK_OEM_5 = 0xDC; // '\|' for US public final static int VK_OEM_6 = 0xDD; // ']}' for US public final static int VK_OEM_7 = 0xDE; // ''"' for US public final static int VK_OEM_8 = 0xDF; /* * 0xE0 : reserved */ /* * Various extended or enhanced keyboards */ public final static int VK_OEM_AX = 0xE1; // 'AX' key on Japanese AX kbd public final static int VK_OEM_102 = 0xE2; // "<>" or "\|" on RT 102-key kbd. public final static int VK_ICO_HELP = 0xE3; // Help key on ICO public final static int VK_ICO_00 = 0xE4; // 00 key on ICO public final static int VK_PROCESSKEY = 0xE5; public final static int VK_ICO_CLEAR = 0xE6; public final static int VK_PACKET = 0xE7; /* * 0xE8 : unassigned */ /* * Nokia/Ericsson definitions */ public final static int VK_OEM_RESET = 0xE9; public final static int VK_OEM_JUMP = 0xEA; public final static int VK_OEM_PA1 = 0xEB; public final static int VK_OEM_PA2 = 0xEC; public final static int VK_OEM_PA3 = 0xED; public final static int VK_OEM_WSCTRL = 0xEE; public final static int VK_OEM_CUSEL = 0xEF; public final static int VK_OEM_ATTN = 0xF0; public final static int VK_OEM_FINISH = 0xF1; public final static int VK_OEM_COPY = 0xF2; public final static int VK_OEM_AUTO = 0xF3; public final static int VK_OEM_ENLW = 0xF4; public final static int VK_OEM_BACKTAB = 0xF5; public final static int VK_ATTN = 0xF6; public final static int VK_CRSEL = 0xF7; public final static int VK_EXSEL = 0xF8; public final static int VK_EREOF = 0xF9; public final static int VK_PLAY = 0xFA; public final static int VK_ZOOM = 0xFB; public final static int VK_NONAME = 0xFC; public final static int VK_PA1 = 0xFD; public final static int VK_OEM_CLEAR = 0xFE; public final static Component.Identifier.Key mapVKey(int vkey) { switch (vkey) { case VK_ESCAPE: return Component.Identifier.Key.ESCAPE; case VK_1: return Component.Identifier.Key._1; case VK_2: return Component.Identifier.Key._2; case VK_3: return Component.Identifier.Key._3; case VK_4: return Component.Identifier.Key._4; case VK_5: return Component.Identifier.Key._5; case VK_6: return Component.Identifier.Key._6; case VK_7: return Component.Identifier.Key._7; case VK_8: return Component.Identifier.Key._8; case VK_9: return Component.Identifier.Key._9; case VK_0: return Component.Identifier.Key._0; case VK_OEM_NEC_EQUAL: return Component.Identifier.Key.NUMPADEQUAL; case VK_BACK: return Component.Identifier.Key.BACK; case VK_TAB: return Component.Identifier.Key.TAB; case VK_Q: return Component.Identifier.Key.Q; case VK_W: return Component.Identifier.Key.W; case VK_E: return Component.Identifier.Key.E; case VK_R: return Component.Identifier.Key.R; case VK_T: return Component.Identifier.Key.T; case VK_Y: return Component.Identifier.Key.Y; case VK_U: return Component.Identifier.Key.U; case VK_I: return Component.Identifier.Key.I; case VK_O: return Component.Identifier.Key.O; case VK_P: return Component.Identifier.Key.P; case VK_OEM_4: return Component.Identifier.Key.LBRACKET; case VK_OEM_6: return Component.Identifier.Key.RBRACKET; case VK_RETURN: return Component.Identifier.Key.RETURN; case VK_CONTROL: case VK_LCONTROL: return Component.Identifier.Key.LCONTROL; case VK_A: return Component.Identifier.Key.A; case VK_S: return Component.Identifier.Key.S; case VK_D: return Component.Identifier.Key.D; case VK_F: return Component.Identifier.Key.F; case VK_G: return Component.Identifier.Key.G; case VK_H: return Component.Identifier.Key.H; case VK_J: return Component.Identifier.Key.J; case VK_K: return Component.Identifier.Key.K; case VK_L: return Component.Identifier.Key.L; case VK_OEM_3: return Component.Identifier.Key.GRAVE; case VK_SHIFT: case VK_LSHIFT: return Component.Identifier.Key.LSHIFT; case VK_Z: return Component.Identifier.Key.Z; case VK_X: return Component.Identifier.Key.X; case VK_C: return Component.Identifier.Key.C; case VK_V: return Component.Identifier.Key.V; case VK_B: return Component.Identifier.Key.B; case VK_N: return Component.Identifier.Key.N; case VK_M: return Component.Identifier.Key.M; case VK_OEM_COMMA: return Component.Identifier.Key.COMMA; case VK_OEM_PERIOD: return Component.Identifier.Key.PERIOD; case VK_RSHIFT: return Component.Identifier.Key.RSHIFT; case VK_MULTIPLY: return Component.Identifier.Key.MULTIPLY; case VK_MENU: case VK_LMENU: return Component.Identifier.Key.LALT; case VK_SPACE: return Component.Identifier.Key.SPACE; case VK_CAPITAL: return Component.Identifier.Key.CAPITAL; case VK_F1: return Component.Identifier.Key.F1; case VK_F2: return Component.Identifier.Key.F2; case VK_F3: return Component.Identifier.Key.F3; case VK_F4: return Component.Identifier.Key.F4; case VK_F5: return Component.Identifier.Key.F5; case VK_F6: return Component.Identifier.Key.F6; case VK_F7: return Component.Identifier.Key.F7; case VK_F8: return Component.Identifier.Key.F8; case VK_F9: return Component.Identifier.Key.F9; case VK_F10: return Component.Identifier.Key.F10; case VK_NUMLOCK: return Component.Identifier.Key.NUMLOCK; case VK_SCROLL: return Component.Identifier.Key.SCROLL; case VK_NUMPAD7: return Component.Identifier.Key.NUMPAD7; case VK_NUMPAD8: return Component.Identifier.Key.NUMPAD8; case VK_NUMPAD9: return Component.Identifier.Key.NUMPAD9; case VK_SUBTRACT: return Component.Identifier.Key.SUBTRACT; case VK_NUMPAD4: return Component.Identifier.Key.NUMPAD4; case VK_NUMPAD5: return Component.Identifier.Key.NUMPAD5; case VK_NUMPAD6: return Component.Identifier.Key.NUMPAD6; case VK_ADD: return Component.Identifier.Key.ADD; case VK_NUMPAD1: return Component.Identifier.Key.NUMPAD1; case VK_NUMPAD2: return Component.Identifier.Key.NUMPAD2; case VK_NUMPAD3: return Component.Identifier.Key.NUMPAD3; case VK_NUMPAD0: return Component.Identifier.Key.NUMPAD0; case VK_DECIMAL: return Component.Identifier.Key.DECIMAL; case VK_F11: return Component.Identifier.Key.F11; case VK_F12: return Component.Identifier.Key.F12; case VK_F13: return Component.Identifier.Key.F13; case VK_F14: return Component.Identifier.Key.F14; case VK_F15: return Component.Identifier.Key.F15; case VK_KANA: return Component.Identifier.Key.KANA; case VK_CONVERT: return Component.Identifier.Key.CONVERT; case VK_KANJI: return Component.Identifier.Key.KANJI; case VK_OEM_AX: return Component.Identifier.Key.AX; case VK_RCONTROL: return Component.Identifier.Key.RCONTROL; case VK_SEPARATOR: return Component.Identifier.Key.NUMPADCOMMA; case VK_DIVIDE: return Component.Identifier.Key.DIVIDE; case VK_SNAPSHOT: return Component.Identifier.Key.SYSRQ; case VK_RMENU: return Component.Identifier.Key.RALT; case VK_PAUSE: return Component.Identifier.Key.PAUSE; case VK_HOME: return Component.Identifier.Key.HOME; case VK_UP: return Component.Identifier.Key.UP; case VK_PRIOR: return Component.Identifier.Key.PAGEUP; case VK_LEFT: return Component.Identifier.Key.LEFT; case VK_RIGHT: return Component.Identifier.Key.RIGHT; case VK_END: return Component.Identifier.Key.END; case VK_DOWN: return Component.Identifier.Key.DOWN; case VK_NEXT: return Component.Identifier.Key.PAGEDOWN; case VK_INSERT: return Component.Identifier.Key.INSERT; case VK_DELETE: return Component.Identifier.Key.DELETE; case VK_LWIN: return Component.Identifier.Key.LWIN; case VK_RWIN: return Component.Identifier.Key.RWIN; case VK_APPS: return Component.Identifier.Key.APPS; case VK_SLEEP: return Component.Identifier.Key.SLEEP; default: return Component.Identifier.Key.UNKNOWN; } } } jinput-20100502/plugins/windows/build.xml0000644000175000017500000000604010424764274020222 0ustar twernertwerner jinput-20100502/plugins/OSX/0000755000175000017500000000000011367367567015373 5ustar twernertwernerjinput-20100502/plugins/OSX/src/0000755000175000017500000000000011367367570016154 5ustar twernertwernerjinput-20100502/plugins/OSX/src/native/0000755000175000017500000000000011367367570017442 5ustar twernertwernerjinput-20100502/plugins/OSX/src/native/net_java_games_input_OSXHIDQueue.c0000644000175000017500000001366510424764257026062 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include #include #include #include "net_java_games_input_OSXHIDQueue.h" #include "util.h" #include "macosxutil.h" JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nOpen(JNIEnv *env, jclass unused, jlong address, jint queue_depth) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOReturn ioReturnValue = (*queue)->create(queue, 0, queue_depth); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue open failed: %d\n", ioReturnValue); return; } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nStart(JNIEnv *env, jclass unused, jlong address) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOReturn ioReturnValue = (*queue)->start(queue); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue start failed: %d\n", ioReturnValue); return; } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nStop(JNIEnv *env, jclass unused, jlong address) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOReturn ioReturnValue = (*queue)->stop(queue); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue stop failed: %d\n", ioReturnValue); return; } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nClose(JNIEnv *env, jclass unused, jlong address) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOReturn ioReturnValue = (*queue)->dispose(queue); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue dispose failed: %d\n", ioReturnValue); return; } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nReleaseQueue(JNIEnv *env, jclass unused, jlong address) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOReturn ioReturnValue = (*queue)->Release(queue); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue Release failed: %d\n", ioReturnValue); return; } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nAddElement(JNIEnv *env, jclass unused, jlong address, jlong cookie_address) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)cookie_address; IOReturn ioReturnValue = (*queue)->addElement(queue, cookie, 0); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue addElement failed: %d\n", ioReturnValue); return; } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nRemoveElement(JNIEnv *env, jclass unused, jlong address, jlong cookie_address) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)cookie_address; IOReturn ioReturnValue = (*queue)->removeElement(queue, cookie); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue removeElement failed: %d\n", ioReturnValue); return; } } JNIEXPORT jboolean JNICALL Java_net_java_games_input_OSXHIDQueue_nGetNextEvent(JNIEnv *env, jclass unused, jlong address, jobject event_return) { IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address; IOHIDEventStruct event; AbsoluteTime zeroTime = {0, 0}; IOReturn ioReturnValue = (*queue)->getNextEvent(queue, &event, zeroTime, 0); if (ioReturnValue == kIOReturnUnderrun) { return JNI_FALSE; } else if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Queue getNextEvent failed: %d\n", ioReturnValue); return JNI_FALSE; } copyEvent(env, &event, event_return); if (event.longValue != NULL) { free(event.longValue); } return JNI_TRUE; } jinput-20100502/plugins/OSX/src/native/macosxutil.h0000644000175000017500000000446710424764256022011 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include #include #include extern jobject createMapFromCFDictionary(JNIEnv *env, CFDictionaryRef dict); extern void copyEvent(JNIEnv *env, IOHIDEventStruct *event, jobject event_return); jinput-20100502/plugins/OSX/src/native/net_java_games_input_OSXHIDDevice.c0000644000175000017500000001232410424764256026163 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include #include #include #include "net_java_games_input_OSXHIDDevice.h" #include "util.h" #include "macosxutil.h" JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nReleaseDevice(JNIEnv *env, jclass unused, jlong device_address, jlong interface_address) { io_object_t hidDevice = (io_object_t)device_address; IOHIDDeviceInterface **device_interface = (IOHIDDeviceInterface **)(intptr_t)interface_address;; (*device_interface)->Release(device_interface); IOObjectRelease(hidDevice); } JNIEXPORT jobject JNICALL Java_net_java_games_input_OSXHIDDevice_nGetDeviceProperties(JNIEnv *env, jclass unused, jlong device_address) { io_object_t hidDevice = (io_object_t)device_address; CFMutableDictionaryRef properties; kern_return_t result = IORegistryEntryCreateCFProperties(hidDevice, &properties, kCFAllocatorDefault, kNilOptions); if (result != KERN_SUCCESS) { throwIOException(env, "Failed to create properties for device (%ld)", result); return NULL; } jobject map = createMapFromCFDictionary(env, properties); CFRelease(properties); return map; } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nOpen (JNIEnv * env, jclass unused, jlong lpDevice) { IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice; IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, 0); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Device open failed: %d", ioReturnValue); } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nClose (JNIEnv * env, jclass unused, jlong lpDevice) { IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice; IOReturn ioReturnValue = (*hidDeviceInterface)->close(hidDeviceInterface); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Device close failed: %d", ioReturnValue); } } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nGetElementValue (JNIEnv * env, jclass unused, jlong lpDevice, jlong hidCookie, jobject event_return) { IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice; IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)hidCookie; IOHIDEventStruct event; IOReturn ioReturnValue = (*hidDeviceInterface)->getElementValue(hidDeviceInterface, cookie, &event); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Device getElementValue failed: %d", ioReturnValue); return; } copyEvent(env, &event, event_return); if (event.longValue != NULL) { free(event.longValue); } } JNIEXPORT jlong JNICALL Java_net_java_games_input_OSXHIDDevice_nCreateQueue(JNIEnv *env, jclass unused, jlong device_address) { IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)device_address; IOHIDQueueInterface **queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface); if (queue == NULL) { throwIOException(env, "Could not allocate queue"); return 0; } return (jlong)(intptr_t)queue; } jinput-20100502/plugins/OSX/src/native/net_java_games_input_OSXHIDDeviceIterator.c0000644000175000017500000001360510424764256027700 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include #include #include #include "net_java_games_input_OSXHIDDeviceIterator.h" #include "util.h" JNIEXPORT jlong JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nCreateIterator(JNIEnv *env, jclass unused) { io_iterator_t hidObjectIterator; // Set up a matching dictionary to search the I/O Registry by class // name for all HID class devices // CFMutableDictionaryRef hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey); // Now search I/O Registry for matching devices. // IOServiceGetMatchingServices consumes a reference to the dictionary so we don't have to release it IOReturn ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Failed to create iterator (%ld)\n", ioReturnValue); return 0; } if (hidObjectIterator == IO_OBJECT_NULL) { throwIOException(env, "Failed to create iterator\n"); return 0; } return (jlong)hidObjectIterator; } JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nReleaseIterator(JNIEnv *env, jclass unused, jlong address) { io_iterator_t iterator = (io_iterator_t)address; IOObjectRelease(iterator); } static IOHIDDeviceInterface **createHIDDevice(JNIEnv *env, io_object_t hidDevice) { // io_name_t className; IOHIDDeviceInterface **hidDeviceInterface; IOCFPlugInInterface **plugInInterface; SInt32 score; /* ioReturnValue = IOObjectGetClass(hidDevice, className); if (ioReturnValue != kIOReturnSuccess) { printfJava(env, "Failed to get IOObject class name."); } printfJava(env, "Found device type [%s]\n", className); */ IOReturn ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score); if (ioReturnValue != kIOReturnSuccess) { throwIOException(env, "Couldn't create plugin for device interface (%ld)\n", ioReturnValue); return NULL; } //Call a method of the intermediate plug-in to create the device //interface // HRESULT plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID)&hidDeviceInterface); (*plugInInterface)->Release(plugInInterface); if (plugInResult != S_OK) { throwIOException(env, "Couldn't create HID class device interface (%ld)\n", plugInResult); return NULL; } return hidDeviceInterface; } JNIEXPORT jobject JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nNext(JNIEnv *env, jclass unused, jlong address) { io_iterator_t iterator = (io_iterator_t)address; io_object_t hidDevice; // io_string_t path; // kern_return_t result; hidDevice = IOIteratorNext(iterator); if (hidDevice == MACH_PORT_NULL) return NULL; /* IOResult result = IORegistryEntryGetPath(hidDevice, kIOServicePlane, path); if (result != KERN_SUCCESS) { IOObjectRelease(hidDevice); throwIOException("Failed to get device path (%ld)\n", result); return NULL; } */ IOHIDDeviceInterface **device_interface = createHIDDevice(env, hidDevice); if (device_interface == NULL) { IOObjectRelease(hidDevice); return NULL; } jobject device_object = newJObject(env, "net/java/games/input/OSXHIDDevice", "(JJ)V", (jlong)hidDevice, (jlong)(intptr_t)device_interface); if (device_object == NULL) { (*device_interface)->Release(device_interface); IOObjectRelease(hidDevice); return NULL; } return device_object; } jinput-20100502/plugins/OSX/src/native/build.xml0000644000175000017500000000750211162673326021257 0ustar twernertwerner OSX JInput Native Plugin jinput-20100502/plugins/OSX/src/native/macosxutil.c0000644000175000017500000001653710424764256022005 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include #include #include "util.h" #include "macosxutil.h" typedef struct { JNIEnv *env; jobject map; } dict_context_t; typedef struct { JNIEnv *env; jobjectArray array; jsize index; } array_context_t; static jobject createObjectFromCFObject(JNIEnv *env, CFTypeRef cfobject); static jstring createStringFromCFString(JNIEnv *env, CFStringRef cfstring) { CFIndex unicode_length = CFStringGetLength(cfstring); CFIndex utf8_length = CFStringGetMaximumSizeForEncoding(unicode_length, kCFStringEncodingUTF8); // Allocate buffer large enough, plus \0 terminator char *buffer = (char *)malloc(utf8_length + 1); if (buffer == NULL) return NULL; Boolean result = CFStringGetCString(cfstring, buffer, utf8_length + 1, kCFStringEncodingUTF8); if (!result) { free(buffer); return NULL; } jstring str = (*env)->NewStringUTF(env, buffer); free(buffer); return str; } static jobject createDoubleObjectFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) { double value; Boolean result = CFNumberGetValue(cfnumber, kCFNumberDoubleType, &value); if (!result) return NULL; return newJObject(env, "java/lang/Double", "(D)V", (jdouble)value); } static jobject createLongObjectFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) { SInt64 value; Boolean result = CFNumberGetValue(cfnumber, kCFNumberSInt64Type, &value); if (!result) return NULL; return newJObject(env, "java/lang/Long", "(J)V", (jlong)value); } static jobject createNumberFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) { CFNumberType number_type = CFNumberGetType(cfnumber); switch (number_type) { case kCFNumberSInt8Type: case kCFNumberSInt16Type: case kCFNumberSInt32Type: case kCFNumberSInt64Type: case kCFNumberCharType: case kCFNumberShortType: case kCFNumberIntType: case kCFNumberLongType: case kCFNumberLongLongType: case kCFNumberCFIndexType: return createLongObjectFromCFNumber(env, cfnumber); case kCFNumberFloat32Type: case kCFNumberFloat64Type: case kCFNumberFloatType: case kCFNumberDoubleType: return createDoubleObjectFromCFNumber(env, cfnumber); default: return NULL; } } static void createArrayEntries(const void *value, void *context) { array_context_t *array_context = (array_context_t *)context; jobject jval = createObjectFromCFObject(array_context->env, value); (*array_context->env)->SetObjectArrayElement(array_context->env, array_context->array, array_context->index++, jval); (*array_context->env)->DeleteLocalRef(array_context->env, jval); } static jobject createArrayFromCFArray(JNIEnv *env, CFArrayRef cfarray) { jclass Object_class = (*env)->FindClass(env, "java/lang/Object"); if (Object_class == NULL) return NULL; CFIndex size = CFArrayGetCount(cfarray); CFRange range = {0, size}; jobjectArray array = (*env)->NewObjectArray(env, size, Object_class, NULL); array_context_t array_context; array_context.env = env; array_context.array = array; array_context.index = 0; CFArrayApplyFunction(cfarray, range, createArrayEntries, &array_context); return array; } static jobject createObjectFromCFObject(JNIEnv *env, CFTypeRef cfobject) { CFTypeID type_id = CFGetTypeID(cfobject); if (type_id == CFDictionaryGetTypeID()) { return createMapFromCFDictionary(env, cfobject); } else if (type_id == CFArrayGetTypeID()) { return createArrayFromCFArray(env, cfobject); } else if (type_id == CFStringGetTypeID()) { return createStringFromCFString(env, cfobject); } else if (type_id == CFNumberGetTypeID()) { return createNumberFromCFNumber(env, cfobject); } else { return NULL; } } static void createMapKeys(const void *key, const void *value, void *context) { dict_context_t *dict_context = (dict_context_t *)context; jclass Map_class = (*dict_context->env)->GetObjectClass(dict_context->env, dict_context->map); if (Map_class == NULL) return; jmethodID map_put = (*dict_context->env)->GetMethodID(dict_context->env, Map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); if (map_put == NULL) return; jobject jkey = createObjectFromCFObject(dict_context->env, key); jobject jvalue = createObjectFromCFObject(dict_context->env, value); if (jkey == NULL || jvalue == NULL) return; (*dict_context->env)->CallObjectMethod(dict_context->env, dict_context->map, map_put, jkey, jvalue); (*dict_context->env)->DeleteLocalRef(dict_context->env, jkey); (*dict_context->env)->DeleteLocalRef(dict_context->env, jvalue); } jobject createMapFromCFDictionary(JNIEnv *env, CFDictionaryRef dict) { jobject map = newJObject(env, "java/util/HashMap", "()V"); if (map == NULL) return NULL; dict_context_t dict_context; dict_context.env = env; dict_context.map = map; CFDictionaryApplyFunction(dict, createMapKeys, &dict_context); return map; } void copyEvent(JNIEnv *env, IOHIDEventStruct *event, jobject event_return) { jclass OSXEvent_class = (*env)->GetObjectClass(env, event_return); if (OSXEvent_class == NULL) { return; } jmethodID OSXEvent_set = (*env)->GetMethodID(env, OSXEvent_class, "set", "(JJIJ)V"); if (OSXEvent_set == NULL) { return; } Nanoseconds nanos = AbsoluteToNanoseconds(event->timestamp); uint64_t nanos64= *((uint64_t *)&nanos); (*env)->CallVoidMethod(env, event_return, OSXEvent_set, (jlong)event->type, (jlong)(intptr_t)event->elementCookie, (jint)event->value, (jlong)nanos64); } jinput-20100502/plugins/OSX/src/java/0000755000175000017500000000000011367367567017103 5ustar twernertwernerjinput-20100502/plugins/OSX/src/java/net/0000755000175000017500000000000011367367567017671 5ustar twernertwernerjinput-20100502/plugins/OSX/src/java/net/java/0000755000175000017500000000000011367367567020612 5ustar twernertwernerjinput-20100502/plugins/OSX/src/java/net/java/games/0000755000175000017500000000000011367367567021706 5ustar twernertwernerjinput-20100502/plugins/OSX/src/java/net/java/games/input/0000755000175000017500000000000011367367570023037 5ustar twernertwernerjinput-20100502/plugins/OSX/src/java/net/java/games/input/UsagePage.java0000644000175000017500000001277210424764254025545 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.lang.reflect.Method; /** HID Usage pages * @author elias * @version 1.0 */ final class UsagePage { private final static UsagePage[] map = new UsagePage[0xFF]; public final static UsagePage UNDEFINED = new UsagePage(0x00); public final static UsagePage GENERIC_DESKTOP = new UsagePage(0x01, GenericDesktopUsage.class); public final static UsagePage SIMULATION = new UsagePage(0x02); public final static UsagePage VR = new UsagePage(0x03); public final static UsagePage SPORT = new UsagePage(0x04); public final static UsagePage GAME = new UsagePage(0x05); /* Reserved 0x06 */ public final static UsagePage KEYBOARD_OR_KEYPAD = new UsagePage(0x07, KeyboardUsage.class); /* USB Device Class Definition for Human Interface Devices (HID). Note: the usage type for all key codes is Selector (Sel). */ public final static UsagePage LEDS = new UsagePage(0x08); public final static UsagePage BUTTON = new UsagePage(0x09, ButtonUsage.class); public final static UsagePage ORDINAL = new UsagePage(0x0A); public final static UsagePage TELEPHONY = new UsagePage(0x0B); public final static UsagePage CONSUMER = new UsagePage(0x0C); public final static UsagePage DIGITIZER = new UsagePage(0x0D); /* Reserved 0x0E */ public final static UsagePage PID = new UsagePage(0x0F); /* USB Physical Interface Device definitions for force feedback and related devices. */ public final static UsagePage UNICODE = new UsagePage(0x10); /* Reserved 0x11 - 0x13 */ public final static UsagePage ALPHANUMERIC_DISPLAY = new UsagePage(0x14); /* Reserved 0x15 - 0x7F */ /* Monitor 0x80 - 0x83 USB Device Class Definition for Monitor Devices */ /* Power 0x84 - 0x87 USB Device Class Definition for Power Devices */ public final static UsagePage POWER_DEVICE = new UsagePage(0x84); /* Power Device Page */ public final static UsagePage BATTERY_SYSTEM = new UsagePage(0x85); /* Battery System Page */ /* Reserved 0x88 - 0x8B */ public final static UsagePage BAR_CODE_SCANNER = new UsagePage(0x8C); /* (Point of Sale) USB Device Class Definition for Bar Code Scanner Devices */ public final static UsagePage SCALE = new UsagePage(0x8D); /* (Point of Sale) USB Device Class Definition for Scale Devices */ /* ReservedPointofSalepages 0x8E - 0X8F */ public final static UsagePage CAMERACONTROL= new UsagePage(0x90); /* USB Device Class Definition for Image Class Devices */ public final static UsagePage ARCADE = new UsagePage(0x91); /* OAAF Definitions for arcade and coinop related Devices */ private final Class usage_class; private final int usage_page_id; public final static UsagePage map(int page_id) { if (page_id < 0 || page_id >= map.length) return null; return map[page_id]; } private UsagePage(int page_id, Class usage_class) { map[page_id] = this; this.usage_class = usage_class; this.usage_page_id = page_id; } private UsagePage(int page_id) { this(page_id, null); } public final String toString() { return "UsagePage (0x" + Integer.toHexString(usage_page_id) + ")"; } public final Usage mapUsage(int usage_id) { if (usage_class == null) return null; try { Method map_method = usage_class.getMethod("map", new Class[]{int.class}); Object result = map_method.invoke(null, new Object[]{new Integer(usage_id)}); return (Usage)result; } catch (Exception e) { throw new Error(e); } } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/KeyboardUsage.java0000644000175000017500000005127110424764252026424 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.util.Map; import java.util.HashMap; /** Mapping from Keyboard HID usages to Component.Identifier.Key * @author elias * @version 1.0 */ final class KeyboardUsage implements Usage { private final static KeyboardUsage[] map = new KeyboardUsage[0xFF]; public static final KeyboardUsage ERRORROLLOVER = new KeyboardUsage(0x01); /* ErrorRollOver */ public static final KeyboardUsage POSTFAIL = new KeyboardUsage(0x02); /* POSTFail */ public static final KeyboardUsage ERRORUNDEFINED = new KeyboardUsage(0x03); /* ErrorUndefined */ public static final KeyboardUsage A = new KeyboardUsage(Component.Identifier.Key.A, 0x04); /* a or A */ public static final KeyboardUsage B = new KeyboardUsage(Component.Identifier.Key.B, 0x05); /* b or B */ public static final KeyboardUsage C = new KeyboardUsage(Component.Identifier.Key.C, 0x06); /* c or C */ public static final KeyboardUsage D = new KeyboardUsage(Component.Identifier.Key.D, 0x07); /* d or D */ public static final KeyboardUsage E = new KeyboardUsage(Component.Identifier.Key.E, 0x08); /* e or E */ public static final KeyboardUsage F = new KeyboardUsage(Component.Identifier.Key.F, 0x09); /* f or F */ public static final KeyboardUsage G = new KeyboardUsage(Component.Identifier.Key.G, 0x0A); /* g or G */ public static final KeyboardUsage H = new KeyboardUsage(Component.Identifier.Key.H, 0x0B); /* h or H */ public static final KeyboardUsage I = new KeyboardUsage(Component.Identifier.Key.I, 0x0C); /* i or I */ public static final KeyboardUsage J = new KeyboardUsage(Component.Identifier.Key.J, 0x0D); /* j or J */ public static final KeyboardUsage K = new KeyboardUsage(Component.Identifier.Key.K, 0x0E); /* k or K */ public static final KeyboardUsage L = new KeyboardUsage(Component.Identifier.Key.L, 0x0F); /* l or L */ public static final KeyboardUsage M = new KeyboardUsage(Component.Identifier.Key.M, 0x10); /* m or M */ public static final KeyboardUsage N = new KeyboardUsage(Component.Identifier.Key.N, 0x11); /* n or N */ public static final KeyboardUsage O = new KeyboardUsage(Component.Identifier.Key.O, 0x12); /* o or O */ public static final KeyboardUsage P = new KeyboardUsage(Component.Identifier.Key.P, 0x13); /* p or P */ public static final KeyboardUsage Q = new KeyboardUsage(Component.Identifier.Key.Q, 0x14); /* q or Q */ public static final KeyboardUsage R = new KeyboardUsage(Component.Identifier.Key.R, 0x15); /* r or R */ public static final KeyboardUsage S = new KeyboardUsage(Component.Identifier.Key.S, 0x16); /* s or S */ public static final KeyboardUsage T = new KeyboardUsage(Component.Identifier.Key.T, 0x17); /* t or T */ public static final KeyboardUsage U = new KeyboardUsage(Component.Identifier.Key.U, 0x18); /* u or U */ public static final KeyboardUsage V = new KeyboardUsage(Component.Identifier.Key.V, 0x19); /* v or V */ public static final KeyboardUsage W = new KeyboardUsage(Component.Identifier.Key.W, 0x1A); /* w or W */ public static final KeyboardUsage X = new KeyboardUsage(Component.Identifier.Key.X, 0x1B); /* x or X */ public static final KeyboardUsage Y = new KeyboardUsage(Component.Identifier.Key.Y, 0x1C); /* y or Y */ public static final KeyboardUsage Z = new KeyboardUsage(Component.Identifier.Key.Z, 0x1D); /* z or Z */ public static final KeyboardUsage _1 = new KeyboardUsage(Component.Identifier.Key._1, 0x1E); /* 1 or ! */ public static final KeyboardUsage _2 = new KeyboardUsage(Component.Identifier.Key._2, 0x1F); /* 2 or @ */ public static final KeyboardUsage _3 = new KeyboardUsage(Component.Identifier.Key._3, 0x20); /* 3 or # */ public static final KeyboardUsage _4 = new KeyboardUsage(Component.Identifier.Key._4, 0x21); /* 4 or $ */ public static final KeyboardUsage _5 = new KeyboardUsage(Component.Identifier.Key._5, 0x22); /* 5 or % */ public static final KeyboardUsage _6 = new KeyboardUsage(Component.Identifier.Key._6, 0x23); /* 6 or ^ */ public static final KeyboardUsage _7 = new KeyboardUsage(Component.Identifier.Key._7, 0x24); /* 7 or & */ public static final KeyboardUsage _8 = new KeyboardUsage(Component.Identifier.Key._8, 0x25); /* 8 or * */ public static final KeyboardUsage _9 = new KeyboardUsage(Component.Identifier.Key._9, 0x26); /* 9 or ( */ public static final KeyboardUsage _0 = new KeyboardUsage(Component.Identifier.Key._0, 0x27); /* 0 or ) */ public static final KeyboardUsage ENTER = new KeyboardUsage(Component.Identifier.Key.RETURN, 0x28); /* Return (Enter) */ public static final KeyboardUsage ESCAPE = new KeyboardUsage(Component.Identifier.Key.ESCAPE, 0x29); /* Escape */ public static final KeyboardUsage BACKSPACE = new KeyboardUsage(Component.Identifier.Key.BACK, 0x2A); /* Delete (Backspace) */ public static final KeyboardUsage TAB = new KeyboardUsage(Component.Identifier.Key.TAB, 0x2B); /* Tab */ public static final KeyboardUsage SPACEBAR = new KeyboardUsage(Component.Identifier.Key.SPACE, 0x2C); /* Spacebar */ public static final KeyboardUsage HYPHEN = new KeyboardUsage(Component.Identifier.Key.MINUS, 0x2D); /* - or _ */ public static final KeyboardUsage EQUALSIGN = new KeyboardUsage(Component.Identifier.Key.EQUALS, 0x2E); /* = or + */ public static final KeyboardUsage OPENBRACKET = new KeyboardUsage(Component.Identifier.Key.LBRACKET, 0x2F); /* [ or { */ public static final KeyboardUsage CLOSEBRACKET = new KeyboardUsage(Component.Identifier.Key.RBRACKET, 0x30); /* ] or } */ public static final KeyboardUsage BACKSLASH = new KeyboardUsage(Component.Identifier.Key.BACKSLASH, 0x31); /* \ or | */ public static final KeyboardUsage NONUSPOUNT = new KeyboardUsage(Component.Identifier.Key.PERIOD, 0x32); /* Non-US # or _ */ public static final KeyboardUsage SEMICOLON = new KeyboardUsage(Component.Identifier.Key.SEMICOLON, 0x33); /* ; or : */ public static final KeyboardUsage QUOTE = new KeyboardUsage(Component.Identifier.Key.APOSTROPHE, 0x34); /* ' or " */ public static final KeyboardUsage TILDE = new KeyboardUsage(Component.Identifier.Key.GRAVE, 0x35); /* Grave Accent and Tilde */ public static final KeyboardUsage COMMA = new KeyboardUsage(Component.Identifier.Key.COMMA, 0x36); /* , or < */ public static final KeyboardUsage PERIOD = new KeyboardUsage(Component.Identifier.Key.PERIOD, 0x37); /* . or > */ public static final KeyboardUsage SLASH = new KeyboardUsage(Component.Identifier.Key.SLASH, 0x38); /* / or ? */ public static final KeyboardUsage CAPSLOCK = new KeyboardUsage(Component.Identifier.Key.CAPITAL, 0x39); /* Caps Lock */ public static final KeyboardUsage F1 = new KeyboardUsage(Component.Identifier.Key.F1, 0x3A); /* F1 */ public static final KeyboardUsage F2 = new KeyboardUsage(Component.Identifier.Key.F2, 0x3B); /* F2 */ public static final KeyboardUsage F3 = new KeyboardUsage(Component.Identifier.Key.F3, 0x3C); /* F3 */ public static final KeyboardUsage F4 = new KeyboardUsage(Component.Identifier.Key.F4, 0x3D); /* F4 */ public static final KeyboardUsage F5 = new KeyboardUsage(Component.Identifier.Key.F5, 0x3E); /* F5 */ public static final KeyboardUsage F6 = new KeyboardUsage(Component.Identifier.Key.F6, 0x3F); /* F6 */ public static final KeyboardUsage F7 = new KeyboardUsage(Component.Identifier.Key.F7, 0x40); /* F7 */ public static final KeyboardUsage F8 = new KeyboardUsage(Component.Identifier.Key.F8, 0x41); /* F8 */ public static final KeyboardUsage F9 = new KeyboardUsage(Component.Identifier.Key.F9, 0x42); /* F9 */ public static final KeyboardUsage F10 = new KeyboardUsage(Component.Identifier.Key.F10, 0x43); /* F10 */ public static final KeyboardUsage F11 = new KeyboardUsage(Component.Identifier.Key.F11, 0x44); /* F11 */ public static final KeyboardUsage F12 = new KeyboardUsage(Component.Identifier.Key.F12, 0x45); /* F12 */ public static final KeyboardUsage PRINTSCREEN = new KeyboardUsage(Component.Identifier.Key.SYSRQ, 0x46); /* PrintScreen */ public static final KeyboardUsage SCROLLLOCK = new KeyboardUsage(Component.Identifier.Key.SCROLL, 0x47); /* Scroll Lock */ public static final KeyboardUsage PAUSE = new KeyboardUsage(Component.Identifier.Key.PAUSE, 0x48); /* Pause */ public static final KeyboardUsage INSERT = new KeyboardUsage(Component.Identifier.Key.INSERT, 0x49); /* Insert */ public static final KeyboardUsage HOME = new KeyboardUsage(Component.Identifier.Key.HOME, 0x4A); /* Home */ public static final KeyboardUsage PAGEUP = new KeyboardUsage(Component.Identifier.Key.PAGEUP, 0x4B); /* Page Up */ public static final KeyboardUsage DELETE = new KeyboardUsage(Component.Identifier.Key.DELETE, 0x4C); /* Delete Forward */ public static final KeyboardUsage END = new KeyboardUsage(Component.Identifier.Key.END, 0x4D); /* End */ public static final KeyboardUsage PAGEDOWN = new KeyboardUsage(Component.Identifier.Key.PAGEDOWN, 0x4E); /* Page Down */ public static final KeyboardUsage RIGHTARROW = new KeyboardUsage(Component.Identifier.Key.RIGHT, 0x4F); /* Right Arrow */ public static final KeyboardUsage LEFTARROW = new KeyboardUsage(Component.Identifier.Key.LEFT, 0x50); /* Left Arrow */ public static final KeyboardUsage DOWNARROW = new KeyboardUsage(Component.Identifier.Key.DOWN, 0x51); /* Down Arrow */ public static final KeyboardUsage UPARROW = new KeyboardUsage(Component.Identifier.Key.UP, 0x52); /* Up Arrow */ public static final KeyboardUsage KEYPAD_NUMLOCK = new KeyboardUsage(Component.Identifier.Key.NUMLOCK, 0x53); /* Keypad NumLock or Clear */ public static final KeyboardUsage KEYPAD_SLASH = new KeyboardUsage(Component.Identifier.Key.DIVIDE, 0x54); /* Keypad / */ public static final KeyboardUsage KEYPAD_ASTERICK = new KeyboardUsage(0x55); /* Keypad * */ public static final KeyboardUsage KEYPAD_HYPHEN = new KeyboardUsage(Component.Identifier.Key.SUBTRACT, 0x56); /* Keypad - */ public static final KeyboardUsage KEYPAD_PLUS = new KeyboardUsage(Component.Identifier.Key.ADD, 0x57); /* Keypad + */ public static final KeyboardUsage KEYPAD_ENTER = new KeyboardUsage(Component.Identifier.Key.NUMPADENTER, 0x58); /* Keypad Enter */ public static final KeyboardUsage KEYPAD_1 = new KeyboardUsage(Component.Identifier.Key.NUMPAD1, 0x59); /* Keypad 1 or End */ public static final KeyboardUsage KEYPAD_2 = new KeyboardUsage(Component.Identifier.Key.NUMPAD2, 0x5A); /* Keypad 2 or Down Arrow */ public static final KeyboardUsage KEYPAD_3 = new KeyboardUsage(Component.Identifier.Key.NUMPAD3, 0x5B); /* Keypad 3 or Page Down */ public static final KeyboardUsage KEYPAD_4 = new KeyboardUsage(Component.Identifier.Key.NUMPAD4, 0x5C); /* Keypad 4 or Left Arrow */ public static final KeyboardUsage KEYPAD_5 = new KeyboardUsage(Component.Identifier.Key.NUMPAD5, 0x5D); /* Keypad 5 */ public static final KeyboardUsage KEYPAD_6 = new KeyboardUsage(Component.Identifier.Key.NUMPAD6, 0x5E); /* Keypad 6 or Right Arrow */ public static final KeyboardUsage KEYPAD_7 = new KeyboardUsage(Component.Identifier.Key.NUMPAD7, 0x5F); /* Keypad 7 or Home */ public static final KeyboardUsage KEYPAD_8 = new KeyboardUsage(Component.Identifier.Key.NUMPAD8, 0x60); /* Keypad 8 or Up Arrow */ public static final KeyboardUsage KEYPAD_9 = new KeyboardUsage(Component.Identifier.Key.NUMPAD9, 0x61); /* Keypad 9 or Page Up */ public static final KeyboardUsage KEYPAD_0 = new KeyboardUsage(Component.Identifier.Key.NUMPAD0, 0x62); /* Keypad 0 or Insert */ public static final KeyboardUsage KEYPAD_PERIOD = new KeyboardUsage(Component.Identifier.Key.DECIMAL, 0x63); /* Keypad . or Delete */ public static final KeyboardUsage NONUSBACKSLASH = new KeyboardUsage(Component.Identifier.Key.BACKSLASH, 0x64); /* Non-US \ or | */ public static final KeyboardUsage APPLICATION = new KeyboardUsage(Component.Identifier.Key.APPS, 0x65); /* Application */ public static final KeyboardUsage POWER = new KeyboardUsage(Component.Identifier.Key.POWER, 0x66); /* Power */ public static final KeyboardUsage KEYPAD_EQUALSIGN = new KeyboardUsage(Component.Identifier.Key.NUMPADEQUAL, 0x67); /* Keypad = */ public static final KeyboardUsage F13 = new KeyboardUsage(Component.Identifier.Key.F13, 0x68); /* F13 */ public static final KeyboardUsage F14 = new KeyboardUsage(Component.Identifier.Key.F14, 0x69); /* F14 */ public static final KeyboardUsage F15 = new KeyboardUsage(Component.Identifier.Key.F15, 0x6A); /* F15 */ public static final KeyboardUsage F16 = new KeyboardUsage(0x6B); /* F16 */ public static final KeyboardUsage F17 = new KeyboardUsage(0x6C); /* F17 */ public static final KeyboardUsage F18 = new KeyboardUsage(0x6D); /* F18 */ public static final KeyboardUsage F19 = new KeyboardUsage(0x6E); /* F19 */ public static final KeyboardUsage F20 = new KeyboardUsage(0x6F); /* F20 */ public static final KeyboardUsage F21 = new KeyboardUsage(0x70); /* F21 */ public static final KeyboardUsage F22 = new KeyboardUsage(0x71); /* F22 */ public static final KeyboardUsage F23 = new KeyboardUsage(0x72); /* F23 */ public static final KeyboardUsage F24 = new KeyboardUsage(0x73); /* F24 */ public static final KeyboardUsage EXECUTE = new KeyboardUsage(0x74); /* Execute */ public static final KeyboardUsage HELP = new KeyboardUsage(0x75); /* Help */ public static final KeyboardUsage MENU = new KeyboardUsage(0x76); /* Menu */ public static final KeyboardUsage SELECT = new KeyboardUsage(0x77); /* Select */ public static final KeyboardUsage STOP = new KeyboardUsage(Component.Identifier.Key.STOP, 0x78); /* Stop */ public static final KeyboardUsage AGAIN = new KeyboardUsage(0x79); /* Again */ public static final KeyboardUsage UNDO = new KeyboardUsage(0x7A); /* Undo */ public static final KeyboardUsage CUT = new KeyboardUsage(0x7B); /* Cut */ public static final KeyboardUsage COPY = new KeyboardUsage(0x7C); /* Copy */ public static final KeyboardUsage PASTE = new KeyboardUsage(0x7D); /* Paste */ public static final KeyboardUsage FIND = new KeyboardUsage(0x7E); /* Find */ public static final KeyboardUsage MUTE = new KeyboardUsage(0x7F); /* Mute */ public static final KeyboardUsage VOLUMEUP = new KeyboardUsage(0x80); /* Volume Up */ public static final KeyboardUsage VOLUMEDOWN = new KeyboardUsage(0x81); /* Volume Down */ public static final KeyboardUsage LOCKINGCAPSLOCK = new KeyboardUsage(Component.Identifier.Key.CAPITAL, 0x82); /* Locking Caps Lock */ public static final KeyboardUsage LOCKINGNUMLOCK = new KeyboardUsage(Component.Identifier.Key.NUMLOCK, 0x83); /* Locking Num Lock */ public static final KeyboardUsage LOCKINGSCROLLLOCK = new KeyboardUsage(Component.Identifier.Key.SCROLL, 0x84); /* Locking Scroll Lock */ public static final KeyboardUsage KEYPAD_COMMA = new KeyboardUsage(Component.Identifier.Key.COMMA, 0x85); /* Keypad Comma */ public static final KeyboardUsage KEYPAD_EQUALSSIGNAS400 = new KeyboardUsage(0x86); /* Keypad Equal Sign for AS/400 */ public static final KeyboardUsage INTERNATIONAL1 = new KeyboardUsage(0x87); /* International1 */ public static final KeyboardUsage INTERNATIONAL2 = new KeyboardUsage(0x88); /* International2 */ public static final KeyboardUsage INTERNATIONAL3 = new KeyboardUsage(0x89); /* International3 */ public static final KeyboardUsage INTERNATIONAL4 = new KeyboardUsage(0x8A); /* International4 */ public static final KeyboardUsage INTERNATIONAL5 = new KeyboardUsage(0x8B); /* International5 */ public static final KeyboardUsage INTERNATIONAL6 = new KeyboardUsage(0x8C); /* International6 */ public static final KeyboardUsage INTERNATIONAL7 = new KeyboardUsage(0x8D); /* International7 */ public static final KeyboardUsage INTERNATIONAL8 = new KeyboardUsage(0x8E); /* International8 */ public static final KeyboardUsage INTERNATIONAL9 = new KeyboardUsage(0x8F); /* International9 */ public static final KeyboardUsage LANG1 = new KeyboardUsage(0x90); /* LANG1 */ public static final KeyboardUsage LANG2 = new KeyboardUsage(0x91); /* LANG2 */ public static final KeyboardUsage LANG3 = new KeyboardUsage(0x92); /* LANG3 */ public static final KeyboardUsage LANG4 = new KeyboardUsage(0x93); /* LANG4 */ public static final KeyboardUsage LANG5 = new KeyboardUsage(0x94); /* LANG5 */ public static final KeyboardUsage LANG6 = new KeyboardUsage(0x95); /* LANG6 */ public static final KeyboardUsage LANG7 = new KeyboardUsage(0x96); /* LANG7 */ public static final KeyboardUsage LANG8 = new KeyboardUsage(0x97); /* LANG8 */ public static final KeyboardUsage LANG9 = new KeyboardUsage(0x98); /* LANG9 */ public static final KeyboardUsage ALTERNATEERASE = new KeyboardUsage(0x99); /* AlternateErase */ public static final KeyboardUsage SYSREQORATTENTION = new KeyboardUsage(Component.Identifier.Key.SYSRQ, 0x9A); /* SysReq/Attention */ public static final KeyboardUsage CANCEL = new KeyboardUsage(0x9B); /* Cancel */ public static final KeyboardUsage CLEAR = new KeyboardUsage(0x9C); /* Clear */ public static final KeyboardUsage PRIOR = new KeyboardUsage(Component.Identifier.Key.PAGEUP, 0x9D); /* Prior */ public static final KeyboardUsage RETURN = new KeyboardUsage(Component.Identifier.Key.RETURN, 0x9E); /* Return */ public static final KeyboardUsage SEPARATOR = new KeyboardUsage(0x9F); /* Separator */ public static final KeyboardUsage OUT = new KeyboardUsage(0xA0); /* Out */ public static final KeyboardUsage OPER = new KeyboardUsage(0xA1); /* Oper */ public static final KeyboardUsage CLEARORAGAIN = new KeyboardUsage(0xA2); /* Clear/Again */ public static final KeyboardUsage CRSELORPROPS = new KeyboardUsage(0xA3); /* CrSel/Props */ public static final KeyboardUsage EXSEL = new KeyboardUsage(0xA4); /* ExSel */ /* 0xA5-0xDF Reserved */ public static final KeyboardUsage LEFTCONTROL = new KeyboardUsage(Component.Identifier.Key.LCONTROL, 0xE0); /* Left Control */ public static final KeyboardUsage LEFTSHIFT = new KeyboardUsage(Component.Identifier.Key.LSHIFT, 0xE1); /* Left Shift */ public static final KeyboardUsage LEFTALT = new KeyboardUsage(Component.Identifier.Key.LALT, 0xE2); /* Left Alt */ public static final KeyboardUsage LEFTGUI = new KeyboardUsage(Component.Identifier.Key.LWIN, 0xE3); /* Left GUI */ public static final KeyboardUsage RIGHTCONTROL = new KeyboardUsage(Component.Identifier.Key.RCONTROL, 0xE4); /* Right Control */ public static final KeyboardUsage RIGHTSHIFT = new KeyboardUsage(Component.Identifier.Key.RSHIFT, 0xE5); /* Right Shift */ public static final KeyboardUsage RIGHTALT = new KeyboardUsage(Component.Identifier.Key.RALT, 0xE6); /* Right Alt */ public static final KeyboardUsage RIGHTGUI = new KeyboardUsage(Component.Identifier.Key.RWIN, 0xE7); /* Right GUI */ private final int usage; private final Component.Identifier.Key identifier; public final Component.Identifier.Key getIdentifier() { return identifier; } public final static KeyboardUsage map(int usage) { if (usage < 0 || usage >= map.length) return null; return map[usage]; } private KeyboardUsage(int usage) { this(Component.Identifier.Key.UNKNOWN, usage); } private KeyboardUsage(Component.Identifier.Key id, int usage) { this.identifier = id; this.usage = usage; map[usage] = this; } public final String toString() { return "KeyboardUsage (0x" + Integer.toHexString(usage) + ")"; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXControllers.java0000644000175000017500000000545610424764252026603 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** helper methods for OSX specific Controllers * @author elias * @version 1.0 */ final class OSXControllers { private final static OSXEvent osx_event = new OSXEvent(); public final static synchronized float poll(OSXHIDElement element) throws IOException { element.getElementValue(osx_event); return element.convertValue(osx_event.getValue()); } /* synchronized to protect osx_event */ public final static synchronized boolean getNextDeviceEvent(Event event, OSXHIDQueue queue) throws IOException { if (queue.getNextEvent(osx_event)) { OSXComponent component = queue.mapEvent(osx_event); event.set(component, component.getElement().convertValue(osx_event.getValue()), osx_event.getNanos()); return true; } else return false; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXHIDDevice.java0000644000175000017500000003446311273015044026010 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.Iterator; import java.util.logging.Logger; /** OSX HIDManager implementation * @author elias * @author gregorypierce * @version 1.0 */ final class OSXHIDDevice { private final static Logger log = Logger.getLogger(OSXHIDDevice.class.getName()); private final static int AXIS_DEFAULT_MIN_VALUE = 0; private final static int AXIS_DEFAULT_MAX_VALUE = 64*1024; private final static String kIOHIDTransportKey = "Transport"; private final static String kIOHIDVendorIDKey = "VendorID"; private final static String kIOHIDVendorIDSourceKey = "VendorIDSource"; private final static String kIOHIDProductIDKey = "ProductID"; private final static String kIOHIDVersionNumberKey = "VersionNumber"; private final static String kIOHIDManufacturerKey = "Manufacturer"; private final static String kIOHIDProductKey = "Product"; private final static String kIOHIDSerialNumberKey = "SerialNumber"; private final static String kIOHIDCountryCodeKey = "CountryCode"; private final static String kIOHIDLocationIDKey = "LocationID"; private final static String kIOHIDDeviceUsageKey = "DeviceUsage"; private final static String kIOHIDDeviceUsagePageKey = "DeviceUsagePage"; private final static String kIOHIDDeviceUsagePairsKey = "DeviceUsagePairs"; private final static String kIOHIDPrimaryUsageKey = "PrimaryUsage"; private final static String kIOHIDPrimaryUsagePageKey = "PrimaryUsagePage"; private final static String kIOHIDMaxInputReportSizeKey = "MaxInputReportSize"; private final static String kIOHIDMaxOutputReportSizeKey = "MaxOutputReportSize"; private final static String kIOHIDMaxFeatureReportSizeKey = "MaxFeatureReportSize"; private final static String kIOHIDElementKey = "Elements"; private final static String kIOHIDElementCookieKey = "ElementCookie"; private final static String kIOHIDElementTypeKey = "Type"; private final static String kIOHIDElementCollectionTypeKey = "CollectionType"; private final static String kIOHIDElementUsageKey = "Usage"; private final static String kIOHIDElementUsagePageKey = "UsagePage"; private final static String kIOHIDElementMinKey = "Min"; private final static String kIOHIDElementMaxKey = "Max"; private final static String kIOHIDElementScaledMinKey = "ScaledMin"; private final static String kIOHIDElementScaledMaxKey = "ScaledMax"; private final static String kIOHIDElementSizeKey = "Size"; private final static String kIOHIDElementReportSizeKey = "ReportSize"; private final static String kIOHIDElementReportCountKey = "ReportCount"; private final static String kIOHIDElementReportIDKey = "ReportID"; private final static String kIOHIDElementIsArrayKey = "IsArray"; private final static String kIOHIDElementIsRelativeKey = "IsRelative"; private final static String kIOHIDElementIsWrappingKey = "IsWrapping"; private final static String kIOHIDElementIsNonLinearKey = "IsNonLinear"; private final static String kIOHIDElementHasPreferredStateKey = "HasPreferredState"; private final static String kIOHIDElementHasNullStateKey = "HasNullState"; private final static String kIOHIDElementUnitKey = "Unit"; private final static String kIOHIDElementUnitExponentKey = "UnitExponent"; private final static String kIOHIDElementNameKey = "Name"; private final static String kIOHIDElementValueLocationKey = "ValueLocation"; private final static String kIOHIDElementDuplicateIndexKey = "DuplicateIndex"; private final static String kIOHIDElementParentCollectionKey = "ParentCollection"; private final long device_address; private final long device_interface_address; private final Map properties; private boolean released; public OSXHIDDevice(long device_address, long device_interface_address) throws IOException { this.device_address = device_address; this.device_interface_address = device_interface_address; this.properties = getDeviceProperties(); open(); } public final Controller.PortType getPortType() { String transport = (String)properties.get(kIOHIDTransportKey); if (transport == null) return Controller.PortType.UNKNOWN; if (transport.equals("USB")) { return Controller.PortType.USB; } else { return Controller.PortType.UNKNOWN; } } public final String getProductName() { return (String)properties.get(kIOHIDProductKey); } private final OSXHIDElement createElementFromElementProperties(Map element_properties) { /* long size = getLongFromProperties(element_properties, kIOHIDElementSizeKey); // ignore elements that can't fit into the 32 bit value field of a hid event if (size > 32) return null;*/ long element_cookie = getLongFromProperties(element_properties, kIOHIDElementCookieKey); int element_type_id = getIntFromProperties(element_properties, kIOHIDElementTypeKey); ElementType element_type = ElementType.map(element_type_id); int min = (int)getLongFromProperties(element_properties, kIOHIDElementMinKey, AXIS_DEFAULT_MIN_VALUE); int max = (int)getLongFromProperties(element_properties, kIOHIDElementMaxKey, AXIS_DEFAULT_MAX_VALUE); /* long scaled_min = getLongFromProperties(element_properties, kIOHIDElementScaledMinKey, Long.MIN_VALUE); long scaled_max = getLongFromProperties(element_properties, kIOHIDElementScaledMaxKey, Long.MAX_VALUE);*/ UsagePair device_usage_pair = getUsagePair(); boolean default_relative = device_usage_pair != null && (device_usage_pair.getUsage() == GenericDesktopUsage.POINTER || device_usage_pair.getUsage() == GenericDesktopUsage.MOUSE); boolean is_relative = getBooleanFromProperties(element_properties, kIOHIDElementIsRelativeKey, default_relative); /* boolean is_wrapping = getBooleanFromProperties(element_properties, kIOHIDElementIsWrappingKey); boolean is_non_linear = getBooleanFromProperties(element_properties, kIOHIDElementIsNonLinearKey); boolean has_preferred_state = getBooleanFromProperties(element_properties, kIOHIDElementHasPreferredStateKey); boolean has_null_state = getBooleanFromProperties(element_properties, kIOHIDElementHasNullStateKey);*/ int usage = getIntFromProperties(element_properties, kIOHIDElementUsageKey); int usage_page = getIntFromProperties(element_properties, kIOHIDElementUsagePageKey); UsagePair usage_pair = createUsagePair(usage_page, usage); if (usage_pair == null || (element_type != ElementType.INPUT_MISC && element_type != ElementType.INPUT_BUTTON && element_type != ElementType.INPUT_AXIS)) { //log.info("element_type = 0x" + element_type + " | usage = " + usage + " | usage_page = " + usage_page); return null; } else { return new OSXHIDElement(this, usage_pair, element_cookie, element_type, min, max, is_relative); } } private final void addElements(List elements, Map properties) { Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey); if (elements_properties == null) return; for (int i = 0; i < elements_properties.length; i++) { Map element_properties = (Map)elements_properties[i]; OSXHIDElement element = createElementFromElementProperties(element_properties); if (element != null) { elements.add(element); } addElements(elements, element_properties); } } public final List getElements() { List elements = new ArrayList(); addElements(elements, properties); return elements; } private final static long getLongFromProperties(Map properties, String key, long default_value) { Long long_obj = (Long)properties.get(key); if (long_obj == null) return default_value; return long_obj.longValue(); } private final static boolean getBooleanFromProperties(Map properties, String key, boolean default_value) { return getLongFromProperties(properties, key, default_value ? 1 : 0) != 0; } private final static int getIntFromProperties(Map properties, String key) { return (int)getLongFromProperties(properties, key); } private final static long getLongFromProperties(Map properties, String key) { Long long_obj = (Long)properties.get(key); return long_obj.longValue(); } private final static UsagePair createUsagePair(int usage_page_id, int usage_id) { UsagePage usage_page = UsagePage.map(usage_page_id); if (usage_page != null) { Usage usage = usage_page.mapUsage(usage_id); if (usage != null) return new UsagePair(usage_page, usage); } return null; } public final UsagePair getUsagePair() { int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey); int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey); return createUsagePair(usage_page_id, usage_id); } /* public final List getUsagePairs() { List usage_pairs_list = new ArrayList(); Object[] usage_pairs = (Object[])properties.get(kIOHIDDeviceUsagePairsKey); if (usage_pairs == null) { int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey); int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey); UsagePair pair = createUsagePair(usage_page_id, usage_id); if (pair != null) usage_pairs_list.add(pair); } for (int i = 0; i < usage_pairs.length; i++) { Map usage_pair = (Map)usage_pairs[i]; int usage_page_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsagePageKey); int usage_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsageKey); UsagePair pair = createUsagePair(usage_page_id, usage_id); if (pair != null) usage_pairs_list.add(pair); } return usage_pairs_list; } */ private final void dumpProperties() { log.info(toString()); dumpMap("", properties); } private final static void dumpArray(String prefix, Object[] array) { log.info(prefix + "{"); for (int i = 0; i < array.length; i++) { dumpObject(prefix + "\t", array[i]); log.info(prefix + ","); } log.info(prefix + "}"); } private final static void dumpMap(String prefix, Map map) { Iterator keys = map.keySet().iterator(); while (keys.hasNext()) { Object key = keys.next(); Object value = map.get(key); dumpObject(prefix, key); dumpObject(prefix + "\t", value); } } private final static void dumpObject(String prefix, Object obj) { if (obj instanceof Long) { Long l = (Long)obj; log.info(prefix + "0x" + Long.toHexString(l.longValue())); } else if (obj instanceof Map) dumpMap(prefix, (Map)obj); else if (obj.getClass().isArray()) dumpArray(prefix, (Object[])obj); else log.info(prefix + obj); } private final Map getDeviceProperties() throws IOException { return nGetDeviceProperties(device_address); } private final static native Map nGetDeviceProperties(long device_address) throws IOException; public final synchronized void release() throws IOException { try { close(); } finally { released = true; nReleaseDevice(device_address, device_interface_address); } } private final static native void nReleaseDevice(long device_address, long device_interface_address); public final synchronized void getElementValue(long element_cookie, OSXEvent event) throws IOException { checkReleased(); nGetElementValue(device_interface_address, element_cookie, event); } private final static native void nGetElementValue(long device_interface_address, long element_cookie, OSXEvent event) throws IOException; public final synchronized OSXHIDQueue createQueue(int queue_depth) throws IOException { checkReleased(); long queue_address = nCreateQueue(device_interface_address); return new OSXHIDQueue(queue_address, queue_depth); } private final static native long nCreateQueue(long device_interface_address) throws IOException; private final void open() throws IOException { nOpen(device_interface_address); } private final static native void nOpen(long device_interface_address) throws IOException; private final void close() throws IOException { nClose(device_interface_address); } private final static native void nClose(long device_interface_address) throws IOException; private final void checkReleased() throws IOException { if (released) throw new IOException(); } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXMouse.java0000644000175000017500000000542410424764251025357 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents an OSX Mouse * @author elias * @version 1.0 */ final class OSXMouse extends Mouse { private final PortType port; private final OSXHIDQueue queue; protected OSXMouse(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers) { super(device.getProductName(), components, children, rumblers); this.queue = queue; this.port = device.getPortType(); } protected final boolean getNextDeviceEvent(Event event) throws IOException { return OSXControllers.getNextDeviceEvent(event, queue); } protected final void setDeviceEventQueueSize(int size) throws IOException { queue.setQueueDepth(size); } public final PortType getPortType() { return port; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/ButtonUsage.java0000644000175000017500000001110610424764251026127 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.util.Map; import java.util.HashMap; /** Button Usages * @author elias * @version 1.0 */ final class ButtonUsage implements Usage { private final static Map map = new HashMap(); private final int button_id; public final static ButtonUsage map(int button_id) { Integer button_id_obj = new Integer(button_id); ButtonUsage existing = (ButtonUsage)map.get(button_id_obj); if (existing != null) return existing; ButtonUsage new_button = new ButtonUsage(button_id); map.put(button_id_obj, new_button); return new_button; } private ButtonUsage(int button_id) { this.button_id = button_id; } public final Component.Identifier.Button getIdentifier() { switch (button_id) { case 1: return Component.Identifier.Button._0; case 2: return Component.Identifier.Button._1; case 3: return Component.Identifier.Button._2; case 4: return Component.Identifier.Button._3; case 5: return Component.Identifier.Button._4; case 6: return Component.Identifier.Button._5; case 7: return Component.Identifier.Button._6; case 8: return Component.Identifier.Button._7; case 9: return Component.Identifier.Button._8; case 10: return Component.Identifier.Button._9; case 11: return Component.Identifier.Button._10; case 12: return Component.Identifier.Button._11; case 13: return Component.Identifier.Button._12; case 14: return Component.Identifier.Button._13; case 15: return Component.Identifier.Button._14; case 16: return Component.Identifier.Button._15; case 17: return Component.Identifier.Button._16; case 18: return Component.Identifier.Button._17; case 19: return Component.Identifier.Button._18; case 20: return Component.Identifier.Button._19; case 21: return Component.Identifier.Button._20; case 22: return Component.Identifier.Button._21; case 23: return Component.Identifier.Button._22; case 24: return Component.Identifier.Button._23; case 25: return Component.Identifier.Button._24; case 26: return Component.Identifier.Button._25; case 27: return Component.Identifier.Button._26; case 28: return Component.Identifier.Button._27; case 29: return Component.Identifier.Button._28; case 30: return Component.Identifier.Button._29; case 31: return Component.Identifier.Button._30; case 32: return Component.Identifier.Button._31; default: return null; } } public final String toString() { return "ButtonUsage (" + button_id + ")"; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXKeyboard.java0000644000175000017500000000544110424764251026026 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents an OSX Keyboard * @author elias * @version 1.0 */ final class OSXKeyboard extends Keyboard { private final PortType port; private final OSXHIDQueue queue; protected OSXKeyboard(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers) { super(device.getProductName(), components, children, rumblers); this.queue = queue; this.port = device.getPortType(); } protected final boolean getNextDeviceEvent(Event event) throws IOException { return OSXControllers.getNextDeviceEvent(event, queue); } protected final void setDeviceEventQueueSize(int size) throws IOException { queue.setQueueDepth(size); } public final PortType getPortType() { return port; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java0000755000175000017500000002511511227400603027742 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.ArrayList; import java.util.Iterator; import java.util.StringTokenizer; import net.java.games.util.plugins.Plugin; import java.security.AccessController; import java.security.PrivilegedAction; /** OSX HIDManager implementation * @author elias * @author gregorypierce * @version 1.0 */ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugin { private static boolean supported = false; /** * Static utility method for loading native libraries. * It will try to load from either the path given by * the net.java.games.input.librarypath property * or through System.loadLibrary(). * */ static void loadLibrary(final String lib_name) { AccessController.doPrivileged( new PrivilegedAction() { public final Object run() { try { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); else System.loadLibrary(lib_name); } catch (UnsatisfiedLinkError e) { e.printStackTrace(); supported = false; } return null; } }); } static String getPrivilegedProperty(final String property) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property); } }); } static String getPrivilegedProperty(final String property, final String default_value) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property, default_value); } }); } static { String osName = getPrivilegedProperty("os.name", "").trim(); if(osName.equals("Mac OS X")) { // Could check isMacOSXEqualsOrBetterThan in here too. supported = true; loadLibrary("jinput-osx"); } } private final static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) { String os_version = System.getProperty("os.version"); StringTokenizer version_tokenizer = new StringTokenizer(os_version, "."); int major; int minor; try { String major_str = version_tokenizer.nextToken(); String minor_str = version_tokenizer.nextToken(); major = Integer.parseInt(major_str); minor = Integer.parseInt(minor_str); } catch (Exception e) { logln("Exception occurred while trying to determine OS version: " + e); // Best guess, no return false; } return major > major_required || (major == major_required && minor >= minor_required); } private final Controller[] controllers; public OSXEnvironmentPlugin() { if(isSupported()) { this.controllers = enumerateControllers(); } else { this.controllers = new Controller[0]; } } public final Controller[] getControllers() { return controllers; } public boolean isSupported() { return supported; } private final static void addElements(OSXHIDQueue queue, List elements, List components, boolean map_mouse_buttons) throws IOException { Iterator it = elements.iterator(); while (it.hasNext()) { OSXHIDElement element = (OSXHIDElement)it.next(); Component.Identifier id = element.getIdentifier(); if (id == null) continue; if (map_mouse_buttons) { if (id == Component.Identifier.Button._0) { id = Component.Identifier.Button.LEFT; } else if (id == Component.Identifier.Button._1) { id = Component.Identifier.Button.RIGHT; } else if (id == Component.Identifier.Button._2) { id = Component.Identifier.Button.MIDDLE; } } OSXComponent component = new OSXComponent(id, element); components.add(component); queue.addElement(element, component); } } private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List elements) throws IOException { List components = new ArrayList(); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); try { addElements(queue, elements, components, false); } catch (IOException e) { queue.release(); throw e; } Component[] components_array = new Component[components.size()]; components.toArray(components_array); Keyboard keyboard = new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{}); return keyboard; } private final static Mouse createMouseFromDevice(OSXHIDDevice device, List elements) throws IOException { List components = new ArrayList(); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); try { addElements(queue, elements, components, true); } catch (IOException e) { queue.release(); throw e; } Component[] components_array = new Component[components.size()]; components.toArray(components_array); Mouse mouse = new OSXMouse(device, queue, components_array, new Controller[]{}, new Rumbler[]{}); if (mouse.getPrimaryButton() != null && mouse.getX() != null && mouse.getY() != null) { return mouse; } else { queue.release(); return null; } } private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List elements, Controller.Type type) throws IOException { List components = new ArrayList(); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); try { addElements(queue, elements, components, false); } catch (IOException e) { queue.release(); throw e; } Component[] components_array = new Component[components.size()]; components.toArray(components_array); AbstractController controller = new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type); return controller; } private final static void createControllersFromDevice(OSXHIDDevice device, List controllers) throws IOException { UsagePair usage_pair = device.getUsagePair(); if (usage_pair == null) return; List elements = device.getElements(); if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.MOUSE || usage_pair.getUsage() == GenericDesktopUsage.POINTER)) { Controller mouse = createMouseFromDevice(device, elements); if (mouse != null) controllers.add(mouse); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.KEYBOARD || usage_pair.getUsage() == GenericDesktopUsage.KEYPAD)) { Controller keyboard = createKeyboardFromDevice(device, elements); if (keyboard != null) controllers.add(keyboard); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.JOYSTICK) { Controller joystick = createControllerFromDevice(device, elements, Controller.Type.STICK); if (joystick != null) controllers.add(joystick); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.MULTI_AXIS_CONTROLLER) { Controller multiaxis = createControllerFromDevice(device, elements, Controller.Type.STICK); if (multiaxis != null) controllers.add(multiaxis); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) { Controller game_pad = createControllerFromDevice(device, elements, Controller.Type.GAMEPAD); if (game_pad != null) controllers.add(game_pad); } } private final static Controller[] enumerateControllers() { List controllers = new ArrayList(); try { OSXHIDDeviceIterator it = new OSXHIDDeviceIterator(); try { while (true) { OSXHIDDevice device; try { device = it.next(); if (device == null) break; boolean device_used = false; try { int old_size = controllers.size(); createControllersFromDevice(device, controllers); device_used = old_size != controllers.size(); } catch (IOException e) { logln("Failed to create controllers from device: " + device.getProductName()); } if (!device_used) device.release(); } catch (IOException e) { logln("Failed to enumerate device: " + e.getMessage()); } } } finally { it.close(); } } catch (IOException e) { log("Failed to enumerate devices: " + e.getMessage()); return new Controller[]{}; } Controller[] controllers_array = new Controller[controllers.size()]; controllers.toArray(controllers_array); return controllers_array; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXComponent.java0000644000175000017500000000516210424764252026231 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents an OSX Component * @author elias * @version 1.0 */ class OSXComponent extends AbstractComponent { private final OSXHIDElement element; public OSXComponent(Component.Identifier id, OSXHIDElement element) { super(id.getName(), id); this.element = element; } public final boolean isRelative() { return element.isRelative(); } public boolean isAnalog() { return element.isAnalog(); } public final OSXHIDElement getElement() { return element; } protected float poll() throws IOException { return OSXControllers.poll(element); } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXAbstractController.java0000644000175000017500000000565510424764252030105 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents an OSX AbstractController * @author elias * @version 1.0 */ final class OSXAbstractController extends AbstractController { private final PortType port; private final OSXHIDQueue queue; private final Type type; protected OSXAbstractController(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers, Type type) { super(device.getProductName(), components, children, rumblers); this.queue = queue; this.type = type; this.port = device.getPortType(); } protected final boolean getNextDeviceEvent(Event event) throws IOException { return OSXControllers.getNextDeviceEvent(event, queue); } protected final void setDeviceEventQueueSize(int size) throws IOException { queue.setQueueDepth(size); } public Type getType() { return type; } public final PortType getPortType() { return port; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/UsagePair.java0000644000175000017500000000547410424764254025565 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** Usage/Page pair * @author elias * @version 1.0 */ class UsagePair { private final UsagePage usage_page; private final Usage usage; public UsagePair(UsagePage usage_page, Usage usage) { this.usage_page = usage_page; this.usage = usage; } public final UsagePage getUsagePage() { return usage_page; } public final Usage getUsage() { return usage; } public final int hashCode() { return usage.hashCode() ^ usage_page.hashCode(); } public final boolean equals(Object other) { if (!(other instanceof UsagePair)) return false; UsagePair other_pair = (UsagePair)other; return other_pair.usage.equals(usage) && other_pair.usage_page.equals(usage_page); } public final String toString() { return "UsagePair: (page = " + usage_page + ", usage = " + usage + ")"; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/Usage.java0000644000175000017500000000416410424764254024744 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** Generic Desktop Usages * @author elias * @version 1.0 */ public interface Usage { } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXHIDElement.java0000644000175000017500000001142010424764253026200 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents an OSX HID Element * @author elias * @author gregorypierce * @version 1.0 */ final class OSXHIDElement { private final OSXHIDDevice device; private final UsagePair usage_pair; private final long element_cookie; private final ElementType element_type; private final int min; private final int max; private final Component.Identifier identifier; private final boolean is_relative; public OSXHIDElement(OSXHIDDevice device, UsagePair usage_pair, long element_cookie, ElementType element_type, int min, int max, boolean is_relative) { this.device = device; this.usage_pair = usage_pair; this.element_cookie = element_cookie; this.element_type = element_type; this.min = min; this.max = max; this.identifier = computeIdentifier(); this.is_relative = is_relative; } private final Component.Identifier computeIdentifier() { if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP) { return ((GenericDesktopUsage)usage_pair.getUsage()).getIdentifier(); } else if (usage_pair.getUsagePage() == UsagePage.BUTTON) { return ((ButtonUsage)usage_pair.getUsage()).getIdentifier(); } else if (usage_pair.getUsagePage() == UsagePage.KEYBOARD_OR_KEYPAD) { return ((KeyboardUsage)usage_pair.getUsage()).getIdentifier(); } else return null; } final Component.Identifier getIdentifier() { return identifier; } final long getCookie() { return element_cookie; } final ElementType getType() { return element_type; } final boolean isRelative() { return is_relative && identifier instanceof Component.Identifier.Axis; } final boolean isAnalog() { return identifier instanceof Component.Identifier.Axis && identifier != Component.Identifier.Axis.POV; } private UsagePair getUsagePair() { return usage_pair; } final void getElementValue(OSXEvent event) throws IOException { device.getElementValue(element_cookie, event); } final float convertValue(float value) { if (identifier == Component.Identifier.Axis.POV) { switch ((int)value) { case 0: return Component.POV.UP; case 1: return Component.POV.UP_RIGHT; case 2: return Component.POV.RIGHT; case 3: return Component.POV.DOWN_RIGHT; case 4: return Component.POV.DOWN; case 5: return Component.POV.DOWN_LEFT; case 6: return Component.POV.LEFT; case 7: return Component.POV.UP_LEFT; case 8: return Component.POV.OFF; default: return Component.POV.OFF; } } else if (identifier instanceof Component.Identifier.Axis && !is_relative) { if (min == max) return 0; else if (value > max) value = max; else if (value < min) value = min; return 2*(value - min)/(max - min) - 1; } else return value; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/ElementType.java0000644000175000017500000000610010424764251026120 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.lang.reflect.Method; /** HID Element types * @author elias * @version 1.0 */ final class ElementType { private final static ElementType[] map = new ElementType[514]; public final static ElementType INPUT_MISC = new ElementType(1); public final static ElementType INPUT_BUTTON = new ElementType(2); public final static ElementType INPUT_AXIS = new ElementType(3); public final static ElementType INPUT_SCANCODES = new ElementType(4); public final static ElementType OUTPUT = new ElementType(129); public final static ElementType FEATURE = new ElementType(257); public final static ElementType COLLECTION = new ElementType(513); private final int type_id; public final static ElementType map(int type_id) { if (type_id < 0 || type_id >= map.length) return null; return map[type_id]; } private ElementType(int type_id) { map[type_id] = this; this.type_id = type_id; } public final String toString() { return "ElementType (0x" + Integer.toHexString(type_id) + ")"; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/GenericDesktopUsage.java0000644000175000017500000002330310525664641027570 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** Generic Desktop Usages * @author elias * @version 1.0 */ final class GenericDesktopUsage implements Usage { private final static GenericDesktopUsage[] map = new GenericDesktopUsage[0xFF]; public final static GenericDesktopUsage POINTER = new GenericDesktopUsage(0x01); /* Physical Collection */ public final static GenericDesktopUsage MOUSE = new GenericDesktopUsage(0x02); /* Application Collection */ /* 0x03 Reserved */ public final static GenericDesktopUsage JOYSTICK = new GenericDesktopUsage(0x04); /* Application Collection */ public final static GenericDesktopUsage GAME_PAD = new GenericDesktopUsage(0x05); /* Application Collection */ public final static GenericDesktopUsage KEYBOARD = new GenericDesktopUsage(0x06); /* Application Collection */ public final static GenericDesktopUsage KEYPAD = new GenericDesktopUsage(0x07); /* Application Collection */ public final static GenericDesktopUsage MULTI_AXIS_CONTROLLER = new GenericDesktopUsage(0x08); /* Application Collection */ /* 0x09 - 0x2F Reserved */ public final static GenericDesktopUsage X = new GenericDesktopUsage(0x30); /* Dynamic Value */ public final static GenericDesktopUsage Y = new GenericDesktopUsage(0x31); /* Dynamic Value */ public final static GenericDesktopUsage Z = new GenericDesktopUsage(0x32); /* Dynamic Value */ public final static GenericDesktopUsage RX = new GenericDesktopUsage(0x33); /* Dynamic Value */ public final static GenericDesktopUsage RY = new GenericDesktopUsage(0x34); /* Dynamic Value */ public final static GenericDesktopUsage RZ = new GenericDesktopUsage(0x35); /* Dynamic Value */ public final static GenericDesktopUsage SLIDER = new GenericDesktopUsage(0x36); /* Dynamic Value */ public final static GenericDesktopUsage DIAL = new GenericDesktopUsage(0x37); /* Dynamic Value */ public final static GenericDesktopUsage WHEEL = new GenericDesktopUsage(0x38); /* Dynamic Value */ public final static GenericDesktopUsage HATSWITCH = new GenericDesktopUsage(0x39); /* Dynamic Value */ public final static GenericDesktopUsage COUNTED_BUFFER = new GenericDesktopUsage(0x3A); /* Logical Collection */ public final static GenericDesktopUsage BYTE_COUNT = new GenericDesktopUsage(0x3B); /* Dynamic Value */ public final static GenericDesktopUsage MOTION_WAKEUP = new GenericDesktopUsage(0x3C); /* One-Shot Control */ public final static GenericDesktopUsage START = new GenericDesktopUsage(0x3D); /* On/Off Control */ public final static GenericDesktopUsage SELECT = new GenericDesktopUsage(0x3E); /* On/Off Control */ /* 0x3F Reserved */ public final static GenericDesktopUsage VX = new GenericDesktopUsage(0x40); /* Dynamic Value */ public final static GenericDesktopUsage VY = new GenericDesktopUsage(0x41); /* Dynamic Value */ public final static GenericDesktopUsage VZ = new GenericDesktopUsage(0x42); /* Dynamic Value */ public final static GenericDesktopUsage VBRX = new GenericDesktopUsage(0x43); /* Dynamic Value */ public final static GenericDesktopUsage VBRY = new GenericDesktopUsage(0x44); /* Dynamic Value */ public final static GenericDesktopUsage VBRZ = new GenericDesktopUsage(0x45); /* Dynamic Value */ public final static GenericDesktopUsage VNO = new GenericDesktopUsage(0x46); /* Dynamic Value */ /* 0x47 - 0x7F Reserved */ public final static GenericDesktopUsage SYSTEM_CONTROL = new GenericDesktopUsage(0x80); /* Application Collection */ public final static GenericDesktopUsage SYSTEM_POWER_DOWN = new GenericDesktopUsage(0x81); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_SLEEP = new GenericDesktopUsage(0x82); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_WAKE_UP = new GenericDesktopUsage(0x83); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_CONTEXT_MENU = new GenericDesktopUsage(0x84); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_MAIN_MENU = new GenericDesktopUsage(0x85); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_APP_MENU = new GenericDesktopUsage(0x86); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_MENU_HELP = new GenericDesktopUsage(0x87); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_MENU_EXIT = new GenericDesktopUsage(0x88); /* One-Shot Control */ public final static GenericDesktopUsage SYSTEM_MENU = new GenericDesktopUsage(0x89); /* Selector */ public final static GenericDesktopUsage SYSTEM_MENU_RIGHT = new GenericDesktopUsage(0x8A); /* Re-Trigger Control */ public final static GenericDesktopUsage SYSTEM_MENU_LEFT = new GenericDesktopUsage(0x8B); /* Re-Trigger Control */ public final static GenericDesktopUsage SYSTEM_MENU_UP = new GenericDesktopUsage(0x8C); /* Re-Trigger Control */ public final static GenericDesktopUsage SYSTEM_MENU_DOWN = new GenericDesktopUsage(0x8D); /* Re-Trigger Control */ /* 0x8E - 0x8F Reserved */ public final static GenericDesktopUsage DPAD_UP = new GenericDesktopUsage(0x90); /* On/Off Control */ public final static GenericDesktopUsage DPAD_DOWN = new GenericDesktopUsage(0x91); /* On/Off Control */ public final static GenericDesktopUsage DPAD_RIGHT = new GenericDesktopUsage(0x92); /* On/Off Control */ public final static GenericDesktopUsage DPAD_LEFT = new GenericDesktopUsage(0x93); /* On/Off Control */ /* 0x94 - 0xFFFF Reserved */ private final int usage_id; public final static GenericDesktopUsage map(int usage_id) { if (usage_id < 0 || usage_id >= map.length) return null; return map[usage_id]; } private GenericDesktopUsage(int usage_id) { map[usage_id] = this; this.usage_id = usage_id; } public final String toString() { return "GenericDesktopUsage (0x" + Integer.toHexString(usage_id) + ")"; } public final Component.Identifier getIdentifier() { if (this == GenericDesktopUsage.X) { return Component.Identifier.Axis.X; } else if (this == GenericDesktopUsage.Y) { return Component.Identifier.Axis.Y; } else if (this == GenericDesktopUsage.Z || this == GenericDesktopUsage.WHEEL) { return Component.Identifier.Axis.Z; } else if (this == GenericDesktopUsage.RX) { return Component.Identifier.Axis.RX; } else if (this == GenericDesktopUsage.RY) { return Component.Identifier.Axis.RY; } else if (this == GenericDesktopUsage.RZ) { return Component.Identifier.Axis.RZ; } else if (this == GenericDesktopUsage.SLIDER) { return Component.Identifier.Axis.SLIDER; } else if (this == GenericDesktopUsage.HATSWITCH) { return Component.Identifier.Axis.POV; } else if (this == GenericDesktopUsage.SELECT) { return Component.Identifier.Button.SELECT; } else return null; } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXHIDDeviceIterator.java0000644000175000017500000000530410424764253027524 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** OSX HIDManager implementation * @author elias * @author gregorypierce * @version 1.0 */ final class OSXHIDDeviceIterator { private final long iterator_address; public OSXHIDDeviceIterator() throws IOException { this.iterator_address = nCreateIterator(); } private final static native long nCreateIterator(); public final void close(){ nReleaseIterator(iterator_address); } private final static native void nReleaseIterator(long iterator_address); public final OSXHIDDevice next() throws IOException { return nNext(iterator_address); } private final static native OSXHIDDevice nNext(long iterator_address) throws IOException; } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXHIDQueue.java0000644000175000017500000001145310424764253025701 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; import java.util.Map; import java.util.HashMap; /** * @author elias * @version 1.0 */ final class OSXHIDQueue { private final Map map = new HashMap(); private final long queue_address; private boolean released; public OSXHIDQueue(long address, int queue_depth) throws IOException { this.queue_address = address; try { createQueue(queue_depth); } catch (IOException e) { release(); throw e; } } public final synchronized void setQueueDepth(int queue_depth) throws IOException { checkReleased(); stop(); close(); createQueue(queue_depth); } private final void createQueue(int queue_depth) throws IOException { open(queue_depth); try { start(); } catch (IOException e) { close(); throw e; } } public final OSXComponent mapEvent(OSXEvent event) { return (OSXComponent)map.get(new Long(event.getCookie())); } private final void open(int queue_depth) throws IOException { nOpen(queue_address, queue_depth); } private final static native void nOpen(long queue_address, int queue_depth) throws IOException; private final void close() throws IOException { nClose(queue_address); } private final static native void nClose(long queue_address) throws IOException; private final void start() throws IOException { nStart(queue_address); } private final static native void nStart(long queue_address) throws IOException; private final void stop() throws IOException { nStop(queue_address); } private final static native void nStop(long queue_address) throws IOException; public final synchronized void release() throws IOException { if (!released) { released = true; try { stop(); close(); } finally { nReleaseQueue(queue_address); } } } private final static native void nReleaseQueue(long queue_address) throws IOException; public final void addElement(OSXHIDElement element, OSXComponent component) throws IOException { nAddElement(queue_address, element.getCookie()); map.put(new Long(element.getCookie()), component); } private final static native void nAddElement(long queue_address, long cookie) throws IOException; public final void removeElement(OSXHIDElement element) throws IOException { nRemoveElement(queue_address, element.getCookie()); map.remove(new Long(element.getCookie())); } private final static native void nRemoveElement(long queue_address, long cookie) throws IOException; public final synchronized boolean getNextEvent(OSXEvent event) throws IOException { checkReleased(); return nGetNextEvent(queue_address, event); } private final static native boolean nGetNextEvent(long queue_address, OSXEvent event) throws IOException; private final void checkReleased() throws IOException { if (released) throw new IOException("Queue is released"); } } jinput-20100502/plugins/OSX/src/java/net/java/games/input/OSXEvent.java0000644000175000017500000000506310424764253025351 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; /** OSX Event structure corresponding to IOHIDEventStruct * @author elias * @version 1.0 */ class OSXEvent { private long type; private long cookie; private int value; private long nanos; public void set(long type, long cookie, int value, long nanos) { this.type = type; this.cookie = cookie; this.value = value; this.nanos = nanos; } public long getType() { return type; } public long getCookie() { return cookie; } public int getValue() { return value; } public long getNanos() { return nanos; } } jinput-20100502/plugins/OSX/build.xml0000644000175000017500000000540610424764250017200 0ustar twernertwerner OSX JInput Plugin jinput-20100502/plugins/awt/0000755000175000017500000000000011367367570015507 5ustar twernertwernerjinput-20100502/plugins/awt/src/0000755000175000017500000000000011367367570016276 5ustar twernertwernerjinput-20100502/plugins/awt/src/net/0000755000175000017500000000000011367367570017064 5ustar twernertwernerjinput-20100502/plugins/awt/src/net/java/0000755000175000017500000000000011367367570020005 5ustar twernertwernerjinput-20100502/plugins/awt/src/net/java/games/0000755000175000017500000000000011367367570021101 5ustar twernertwernerjinput-20100502/plugins/awt/src/net/java/games/input/0000755000175000017500000000000011367367570022240 5ustar twernertwernerjinput-20100502/plugins/awt/src/net/java/games/input/AWTEnvironmentPlugin.java0000644000175000017500000000377310633011276027134 0ustar twernertwerner/** * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import net.java.games.input.Controller; import net.java.games.input.ControllerEnvironment; import net.java.games.util.plugins.Plugin; /** * @author Jeremy * @author elias */ public class AWTEnvironmentPlugin extends ControllerEnvironment implements Plugin { private final Controller[] controllers; public AWTEnvironmentPlugin() { this.controllers = new Controller[]{new AWTKeyboard(), new AWTMouse()}; } public Controller[] getControllers() { return controllers; } public boolean isSupported() { return true; } } jinput-20100502/plugins/awt/src/net/java/games/input/AWTKeyMap.java0000644000175000017500000002330310424764260024634 0ustar twernertwerner/** * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.awt.event.KeyEvent; /** * @author Jeremy * @author elias */ final class AWTKeyMap { public final static Component.Identifier.Key mapKeyCode(int key_code) { switch (key_code) { case KeyEvent.VK_0: return Component.Identifier.Key._0; case KeyEvent.VK_1: return Component.Identifier.Key._1; case KeyEvent.VK_2: return Component.Identifier.Key._2; case KeyEvent.VK_3: return Component.Identifier.Key._3; case KeyEvent.VK_4: return Component.Identifier.Key._4; case KeyEvent.VK_5: return Component.Identifier.Key._5; case KeyEvent.VK_6: return Component.Identifier.Key._6; case KeyEvent.VK_7: return Component.Identifier.Key._7; case KeyEvent.VK_8: return Component.Identifier.Key._8; case KeyEvent.VK_9: return Component.Identifier.Key._9; case KeyEvent.VK_Q: return Component.Identifier.Key.Q; case KeyEvent.VK_W: return Component.Identifier.Key.W; case KeyEvent.VK_E: return Component.Identifier.Key.E; case KeyEvent.VK_R: return Component.Identifier.Key.R; case KeyEvent.VK_T: return Component.Identifier.Key.T; case KeyEvent.VK_Y: return Component.Identifier.Key.Y; case KeyEvent.VK_U: return Component.Identifier.Key.U; case KeyEvent.VK_I: return Component.Identifier.Key.I; case KeyEvent.VK_O: return Component.Identifier.Key.O; case KeyEvent.VK_P: return Component.Identifier.Key.P; case KeyEvent.VK_A: return Component.Identifier.Key.A; case KeyEvent.VK_S: return Component.Identifier.Key.S; case KeyEvent.VK_D: return Component.Identifier.Key.D; case KeyEvent.VK_F: return Component.Identifier.Key.F; case KeyEvent.VK_G: return Component.Identifier.Key.G; case KeyEvent.VK_H: return Component.Identifier.Key.H; case KeyEvent.VK_J: return Component.Identifier.Key.J; case KeyEvent.VK_K: return Component.Identifier.Key.K; case KeyEvent.VK_L: return Component.Identifier.Key.L; case KeyEvent.VK_Z: return Component.Identifier.Key.Z; case KeyEvent.VK_X: return Component.Identifier.Key.X; case KeyEvent.VK_C: return Component.Identifier.Key.C; case KeyEvent.VK_V: return Component.Identifier.Key.V; case KeyEvent.VK_B: return Component.Identifier.Key.B; case KeyEvent.VK_N: return Component.Identifier.Key.N; case KeyEvent.VK_M: return Component.Identifier.Key.M; case KeyEvent.VK_F1: return Component.Identifier.Key.F1; case KeyEvent.VK_F2: return Component.Identifier.Key.F2; case KeyEvent.VK_F3: return Component.Identifier.Key.F3; case KeyEvent.VK_F4: return Component.Identifier.Key.F4; case KeyEvent.VK_F5: return Component.Identifier.Key.F5; case KeyEvent.VK_F6: return Component.Identifier.Key.F6; case KeyEvent.VK_F7: return Component.Identifier.Key.F7; case KeyEvent.VK_F8: return Component.Identifier.Key.F8; case KeyEvent.VK_F9: return Component.Identifier.Key.F9; case KeyEvent.VK_F10: return Component.Identifier.Key.F10; case KeyEvent.VK_F11: return Component.Identifier.Key.F11; case KeyEvent.VK_F12: return Component.Identifier.Key.F12; case KeyEvent.VK_ESCAPE: return Component.Identifier.Key.ESCAPE; case KeyEvent.VK_MINUS: return Component.Identifier.Key.MINUS; case KeyEvent.VK_EQUALS: return Component.Identifier.Key.EQUALS; case KeyEvent.VK_BACK_SPACE: return Component.Identifier.Key.BACKSLASH; case KeyEvent.VK_TAB: return Component.Identifier.Key.TAB; case KeyEvent.VK_OPEN_BRACKET: return Component.Identifier.Key.LBRACKET; case KeyEvent.VK_CLOSE_BRACKET: return Component.Identifier.Key.RBRACKET; case KeyEvent.VK_SEMICOLON: return Component.Identifier.Key.SEMICOLON; case KeyEvent.VK_QUOTE: return Component.Identifier.Key.APOSTROPHE; case KeyEvent.VK_NUMBER_SIGN: return Component.Identifier.Key.GRAVE; case KeyEvent.VK_BACK_SLASH: return Component.Identifier.Key.BACKSLASH; case KeyEvent.VK_PERIOD: return Component.Identifier.Key.PERIOD; case KeyEvent.VK_SLASH: return Component.Identifier.Key.SLASH; case KeyEvent.VK_MULTIPLY: return Component.Identifier.Key.MULTIPLY; case KeyEvent.VK_SPACE: return Component.Identifier.Key.SPACE; case KeyEvent.VK_CAPS_LOCK: return Component.Identifier.Key.CAPITAL; case KeyEvent.VK_NUM_LOCK: return Component.Identifier.Key.NUMLOCK; case KeyEvent.VK_SCROLL_LOCK: return Component.Identifier.Key.SCROLL; case KeyEvent.VK_NUMPAD7: return Component.Identifier.Key.NUMPAD7; case KeyEvent.VK_NUMPAD8: return Component.Identifier.Key.NUMPAD8; case KeyEvent.VK_NUMPAD9: return Component.Identifier.Key.NUMPAD9; case KeyEvent.VK_SUBTRACT: return Component.Identifier.Key.SUBTRACT; case KeyEvent.VK_NUMPAD4: return Component.Identifier.Key.NUMPAD4; case KeyEvent.VK_NUMPAD5: return Component.Identifier.Key.NUMPAD5; case KeyEvent.VK_NUMPAD6: return Component.Identifier.Key.NUMPAD6; case KeyEvent.VK_ADD: return Component.Identifier.Key.ADD; case KeyEvent.VK_NUMPAD1: return Component.Identifier.Key.NUMPAD1; case KeyEvent.VK_NUMPAD2: return Component.Identifier.Key.NUMPAD2; case KeyEvent.VK_NUMPAD3: return Component.Identifier.Key.NUMPAD3; case KeyEvent.VK_NUMPAD0: return Component.Identifier.Key.NUMPAD0; case KeyEvent.VK_DECIMAL: return Component.Identifier.Key.DECIMAL; case KeyEvent.VK_KANA: return Component.Identifier.Key.KANA; case KeyEvent.VK_CONVERT: return Component.Identifier.Key.CONVERT; case KeyEvent.VK_NONCONVERT: return Component.Identifier.Key.NOCONVERT; case KeyEvent.VK_CIRCUMFLEX: return Component.Identifier.Key.CIRCUMFLEX; case KeyEvent.VK_AT: return Component.Identifier.Key.AT; case KeyEvent.VK_COLON: return Component.Identifier.Key.COLON; case KeyEvent.VK_UNDERSCORE: return Component.Identifier.Key.UNDERLINE; case KeyEvent.VK_KANJI: return Component.Identifier.Key.KANJI; case KeyEvent.VK_STOP: return Component.Identifier.Key.STOP; case KeyEvent.VK_DIVIDE: return Component.Identifier.Key.DIVIDE; case KeyEvent.VK_PAUSE: return Component.Identifier.Key.PAUSE; case KeyEvent.VK_HOME: return Component.Identifier.Key.HOME; case KeyEvent.VK_UP: return Component.Identifier.Key.UP; case KeyEvent.VK_PAGE_UP: return Component.Identifier.Key.PAGEUP; case KeyEvent.VK_LEFT: return Component.Identifier.Key.LEFT; case KeyEvent.VK_RIGHT: return Component.Identifier.Key.RIGHT; case KeyEvent.VK_END: return Component.Identifier.Key.END; case KeyEvent.VK_DOWN: return Component.Identifier.Key.DOWN; case KeyEvent.VK_PAGE_DOWN: return Component.Identifier.Key.PAGEDOWN; case KeyEvent.VK_INSERT: return Component.Identifier.Key.INSERT; case KeyEvent.VK_DELETE: return Component.Identifier.Key.DELETE; default: return Component.Identifier.Key.UNKNOWN; } } public final static Component.Identifier.Key map(KeyEvent event) { int key_code = event.getKeyCode(); int key_location = event.getKeyLocation(); switch (key_code) { case KeyEvent.VK_CONTROL: if (key_location == KeyEvent.KEY_LOCATION_RIGHT) return Component.Identifier.Key.RCONTROL; else return Component.Identifier.Key.LCONTROL; case KeyEvent.VK_SHIFT: if (key_location == KeyEvent.KEY_LOCATION_RIGHT) return Component.Identifier.Key.RSHIFT; else return Component.Identifier.Key.LSHIFT; case KeyEvent.VK_ALT: if (key_location == KeyEvent.KEY_LOCATION_RIGHT) return Component.Identifier.Key.RALT; else return Component.Identifier.Key.LALT; //this is 1.5 only /* case KeyEvent.VK_WINDOWS: if (key_location == KeyEvent.KEY_LOCATION_RIGHT) return Component.Identifier.Key.RWIN; else return Component.Identifier.Key.LWIN;*/ case KeyEvent.VK_ENTER: if (key_location == KeyEvent.KEY_LOCATION_NUMPAD) return Component.Identifier.Key.NUMPADENTER; else return Component.Identifier.Key.RETURN; case KeyEvent.VK_COMMA: if (key_location == KeyEvent.KEY_LOCATION_NUMPAD) return Component.Identifier.Key.NUMPADCOMMA; else return Component.Identifier.Key.COMMA; default: return mapKeyCode(key_code); } } } jinput-20100502/plugins/awt/src/net/java/games/input/AWTKeyboard.java0000644000175000017500000001357210424764257025223 0ustar twernertwerner/** * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.awt.AWTEvent; import java.awt.Toolkit; import java.awt.event.AWTEventListener; import java.awt.event.KeyEvent; import java.util.List; import java.util.ArrayList; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; /** * @author Jeremy * @author elias */ final class AWTKeyboard extends Keyboard implements AWTEventListener { private final List awt_events = new ArrayList(); private Event[] processed_events; private int processed_events_index; protected AWTKeyboard() { super("AWTKeyboard", createComponents(), new Controller[]{}, new Rumbler[]{}); Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); resizeEventQueue(EVENT_QUEUE_DEPTH); } private final static Component[] createComponents() { List components = new ArrayList(); Field[] vkey_fields = KeyEvent.class.getFields(); for (int i = 0; i < vkey_fields.length; i++) { Field vkey_field = vkey_fields[i]; try { if (Modifier.isStatic(vkey_field.getModifiers()) && vkey_field.getType() == int.class && vkey_field.getName().startsWith("VK_")) { int vkey_code = vkey_field.getInt(null); Component.Identifier.Key key_id = AWTKeyMap.mapKeyCode(vkey_code); if (key_id != Component.Identifier.Key.UNKNOWN) components.add(new Key(key_id)); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } components.add(new Key(Component.Identifier.Key.RCONTROL)); components.add(new Key(Component.Identifier.Key.LCONTROL)); components.add(new Key(Component.Identifier.Key.RSHIFT)); components.add(new Key(Component.Identifier.Key.LSHIFT)); components.add(new Key(Component.Identifier.Key.RALT)); components.add(new Key(Component.Identifier.Key.LALT)); components.add(new Key(Component.Identifier.Key.NUMPADENTER)); components.add(new Key(Component.Identifier.Key.RETURN)); components.add(new Key(Component.Identifier.Key.NUMPADCOMMA)); components.add(new Key(Component.Identifier.Key.COMMA)); return (Component[])components.toArray(new Component[]{}); } private final void resizeEventQueue(int size) { processed_events = new Event[size]; for (int i = 0; i < processed_events.length; i++) processed_events[i] = new Event(); processed_events_index = 0; } protected final void setDeviceEventQueueSize(int size) throws IOException { resizeEventQueue(size); } public final synchronized void eventDispatched(AWTEvent event) { if (event instanceof KeyEvent) awt_events.add(event); } public final synchronized void pollDevice() throws IOException { for (int i = 0; i < awt_events.size(); i++) { KeyEvent event = (KeyEvent)awt_events.get(i); processEvent(event); } awt_events.clear(); } private final void processEvent(KeyEvent event) { Component.Identifier.Key key_id = AWTKeyMap.map(event); if (key_id == null) return; Key key = (Key)getComponent(key_id); if (key == null) return; long nanos = event.getWhen()*1000000L; if (event.getID() == KeyEvent.KEY_PRESSED) { //the key was pressed addEvent(key, 1, nanos); } else if (event.getID() == KeyEvent.KEY_RELEASED) { KeyEvent nextPress = (KeyEvent)Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent(KeyEvent.KEY_PRESSED); if ((nextPress == null) || (nextPress.getWhen() != event.getWhen())) { //the key came really came up addEvent(key, 0, nanos); } } } private final void addEvent(Key key, float value, long nanos) { key.setValue(value); if (processed_events_index < processed_events.length) processed_events[processed_events_index++].set(key, value, nanos); } protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException { if (processed_events_index == 0) return false; processed_events_index--; event.set(processed_events[0]); Event tmp = processed_events[0]; processed_events[0] = processed_events[processed_events_index]; processed_events[processed_events_index] = tmp; return true; } private final static class Key extends AbstractComponent { private float value; public Key(Component.Identifier.Key key_id) { super(key_id.getName(), key_id); } public final void setValue(float value) { this.value = value; } protected final float poll() { return value; } public final boolean isAnalog() { return false; } public final boolean isRelative() { return false; } } } jinput-20100502/plugins/awt/src/net/java/games/input/AWTMouse.java0000644000175000017500000001523210424764257024546 0ustar twernertwerner/** * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.awt.AWTEvent; import java.awt.Point; import java.awt.Toolkit; import java.awt.event.AWTEventListener; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.util.List; import java.util.ArrayList; import java.io.IOException; /** * @author Jeremy * @author elias */ final class AWTMouse extends Mouse implements AWTEventListener { private final static int EVENT_X = 1; private final static int EVENT_Y = 2; private final static int EVENT_BUTTON = 4; private final List awt_events = new ArrayList(); private final List processed_awt_events = new ArrayList(); private int event_state = EVENT_X; protected AWTMouse() { super("AWTMouse", createComponents(), new Controller[]{}, new Rumbler[]{}); Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK); } private final static Component[] createComponents() { return new Component[]{new Axis(Component.Identifier.Axis.X), new Axis(Component.Identifier.Axis.Y), new Axis(Component.Identifier.Axis.Z), new Button(Component.Identifier.Button.LEFT), new Button(Component.Identifier.Button.MIDDLE), new Button(Component.Identifier.Button.RIGHT)}; } private final void processButtons(int button_enum, float value) { Button button = getButton(button_enum); if (button != null) button.setValue(value); } private final Button getButton(int button_enum) { switch (button_enum) { case MouseEvent.BUTTON1: return (Button)getLeft(); case MouseEvent.BUTTON2: return (Button)getMiddle(); case MouseEvent.BUTTON3: return (Button)getRight(); case MouseEvent.NOBUTTON: default: // Unknown button return null; } } private final void processEvent(AWTEvent event) throws IOException { if (event instanceof MouseWheelEvent) { MouseWheelEvent mwe = (MouseWheelEvent)event; Axis wheel = (Axis)getWheel(); wheel.setValue(wheel.poll() + mwe.getWheelRotation()); } else if (event instanceof MouseEvent) { MouseEvent me = (MouseEvent)event; Axis x = (Axis)getX(); Axis y = (Axis)getY(); x.setValue(me.getX()); y.setValue(me.getY()); switch (me.getID()) { case MouseEvent.MOUSE_PRESSED: processButtons(me.getButton(), 1f); break; case MouseEvent.MOUSE_RELEASED: processButtons(me.getButton(), 0f); break; default: break; } } } public final synchronized void pollDevice() throws IOException { Axis wheel = (Axis)getWheel(); wheel.setValue(0); for (int i = 0; i < awt_events.size(); i++) { AWTEvent event = (AWTEvent)awt_events.get(i); processEvent(event); processed_awt_events.add(event); } awt_events.clear(); } protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException { while (true) { if (processed_awt_events.isEmpty()) return false; AWTEvent awt_event = (AWTEvent)processed_awt_events.get(0); if (awt_event instanceof MouseWheelEvent) { MouseWheelEvent awt_wheel_event = (MouseWheelEvent)awt_event; long nanos = awt_wheel_event.getWhen()*1000000L; event.set(getWheel(), awt_wheel_event.getWheelRotation(), nanos); processed_awt_events.remove(0); } else if (awt_event instanceof MouseEvent) { MouseEvent mouse_event = (MouseEvent)awt_event; long nanos = mouse_event.getWhen()*1000000L; switch (event_state) { case EVENT_X: event_state = EVENT_Y; event.set(getX(), mouse_event.getX(), nanos); return true; case EVENT_Y: event_state = EVENT_BUTTON; event.set(getY(), mouse_event.getY(), nanos); return true; case EVENT_BUTTON: processed_awt_events.remove(0); event_state = EVENT_X; Button button = getButton(mouse_event.getButton()); if (button != null) { switch (mouse_event.getID()) { case MouseEvent.MOUSE_PRESSED: event.set(button, 1f, nanos); return true; case MouseEvent.MOUSE_RELEASED: event.set(button, 0f, nanos); return true; default: break; } } break; default: throw new RuntimeException("Unknown event state: " + event_state); } } } } public final synchronized void eventDispatched(AWTEvent event) { awt_events.add(event); } final static class Axis extends AbstractComponent { private float value; public Axis(Component.Identifier.Axis axis_id) { super(axis_id.getName(), axis_id); } public final boolean isRelative() { return false; } public final boolean isAnalog() { return true; } protected final void setValue(float value) { this.value = value; } protected final float poll() throws IOException { return value; } } final static class Button extends AbstractComponent { private float value; public Button(Component.Identifier.Button button_id) { super(button_id.getName(), button_id); } protected final void setValue(float value) { this.value = value; } protected final float poll() throws IOException { return value; } public final boolean isAnalog() { return false; } public final boolean isRelative() { return false; } } } jinput-20100502/plugins/awt/build.xml0000644000175000017500000000332410424764257017326 0ustar twernertwerner jinput-20100502/plugins/linux/0000755000175000017500000000000011367367570016053 5ustar twernertwernerjinput-20100502/plugins/linux/src/0000755000175000017500000000000011367367572016644 5ustar twernertwernerjinput-20100502/plugins/linux/src/native/0000755000175000017500000000000011367367572020132 5ustar twernertwernerjinput-20100502/plugins/linux/src/native/getDefinitions0000644000175000017500000000444610424764266023032 0ustar twernertwerner#!/bin/gawk -f # Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. Redistributions in binary # form must reproduce the above copyright notice, this list of conditions and # the following disclaimer in the documentation and/or other materials provided # with the distribution. # The name of the author may not be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE NR == 1 { FILENAME == ARGV[1]; printf("package net.java.games.input;\n\n") printf("\n"); printf("/**\n * This file is generated from %s please do not edit\n */\n", FILENAME); printf("class NativeDefinitions {\n") } /#define ABS_/ { printf(" public static final int %s = %s;\n", $2, $3) } /#define REL_/ { printf(" public static final int %s = %s;\n", $2, $3) } /#define BTN_/ { printf(" public static final int %s = %s;\n", $2, $3) } /#define KEY_/ { printf(" public static final int %s = %s;\n", $2, $3) } /#define BUS_/ { printf(" public static final int %s = %s;\n", $2, $3) } /#define EV_/ { printf(" public static final int %s = %s;\n", $2, $3) } /#define FF_/ { printf(" public static final int %s = %s;\n", $2, $3) } /#define USAGE_/ { printf(" public static final int %s = %s;\n", $2, $3) } END { printf("}\n"); } jinput-20100502/plugins/linux/src/native/net_java_games_input_LinuxEventDevice.c0000644000175000017500000002523310424764266027760 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include #include #include #include #include "util.h" #include "net_java_games_input_LinuxEventDevice.h" JNIEXPORT jlong JNICALL Java_net_java_games_input_LinuxEventDevice_nOpen(JNIEnv *env, jclass unused, jstring path, jboolean rw_flag) { const char *path_str = (*env)->GetStringUTFChars(env, path, NULL); if (path_str == NULL) return -1; int flags = rw_flag == JNI_TRUE ? O_RDWR : O_RDONLY; flags = flags | O_NONBLOCK; int fd = open(path_str, flags); if (fd == -1) throwIOException(env, "Failed to open device %s (%d)\n", path_str, errno); (*env)->ReleaseStringUTFChars(env, path, path_str); return fd; } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nClose(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; int result = close(fd); if (result == -1) throwIOException(env, "Failed to close device (%d)\n", errno); } JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxEventDevice_nGetName(JNIEnv *env, jclass unused, jlong fd_address) { #define BUFFER_SIZE 1024 int fd = (int)fd_address; char device_name[BUFFER_SIZE]; if (ioctl(fd, EVIOCGNAME(BUFFER_SIZE), device_name) == -1) { throwIOException(env, "Failed to get device name (%d)\n", errno); return NULL; } jstring jstr = (*env)->NewStringUTF(env, device_name); return jstr; } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetKeyStates(JNIEnv *env, jclass unused, jlong fd_address, jbyteArray bits_array) { int fd = (int)fd_address; jsize len = (*env)->GetArrayLength(env, bits_array); jbyte *bits = (*env)->GetByteArrayElements(env, bits_array, NULL); if (bits == NULL) return; int res = ioctl(fd, EVIOCGKEY(len), bits); (*env)->ReleaseByteArrayElements(env, bits_array, bits, 0); if (res == -1) throwIOException(env, "Failed to get device key states (%d)\n", errno); } JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetVersion(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; int version; if (ioctl(fd, EVIOCGVERSION, &version) == -1) { throwIOException(env, "Failed to get device version (%d)\n", errno); return -1; } return version; } JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNumEffects(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; int num_effects; if (ioctl(fd, EVIOCGEFFECTS, &num_effects) == -1) { throwIOException(env, "Failed to get number of device effects (%d)\n", errno); return -1; } return num_effects; } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetDeviceUsageBits(JNIEnv *env, jclass unused, jlong fd_address, jbyteArray usages_array) { #if EV_VERSION >= 0x010001 int fd = (int)fd_address; jsize len = (*env)->GetArrayLength(env, usages_array); jbyte *usages = (*env)->GetByteArrayElements(env, usages_array, NULL); if (usages == NULL) return; int res = ioctl(fd, EVIOCGUSAGE(len), usages); (*env)->ReleaseByteArrayElements(env, usages_array, usages, 0); if (res == -1) throwIOException(env, "Failed to get device usages (%d)\n", errno); #endif } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetBits(JNIEnv *env, jclass unused, jlong fd_address, jint evtype, jbyteArray bits_array) { int fd = (int)fd_address; jsize len = (*env)->GetArrayLength(env, bits_array); jbyte *bits = (*env)->GetByteArrayElements(env, bits_array, NULL); if (bits == NULL) return; int res = ioctl(fd, EVIOCGBIT(evtype, len), bits); (*env)->ReleaseByteArrayElements(env, bits_array, bits, 0); if (res == -1) throwIOException(env, "Failed to get device bits (%d)\n", errno); } JNIEXPORT jobject JNICALL Java_net_java_games_input_LinuxEventDevice_nGetInputID(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; jclass input_id_class = (*env)->FindClass(env, "net/java/games/input/LinuxInputID"); if (input_id_class == NULL) return NULL; jmethodID input_id_constructor = (*env)->GetMethodID(env, input_id_class, "", "(IIII)V"); if (input_id_constructor == NULL) return NULL; struct input_id id; int result = ioctl(fd, EVIOCGID, &id); if (result == -1) { throwIOException(env, "Failed to get input id for device (%d)\n", errno); return NULL; } return (*env)->NewObject(env, input_id_class, input_id_constructor, (jint)id.bustype, (jint)id.vendor, (jint)id.product, (jint)id.version); } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nGetAbsInfo(JNIEnv *env, jclass unused, jlong fd_address, jint abs_axis, jobject abs_info_return) { int fd = (int)fd_address; jclass abs_info_class = (*env)->GetObjectClass(env, abs_info_return); if (abs_info_class == NULL) return; jmethodID abs_info_set = (*env)->GetMethodID(env, abs_info_class, "set", "(IIIII)V"); if (abs_info_set == NULL) return; struct input_absinfo abs_info; int result = ioctl(fd, EVIOCGABS(abs_axis), &abs_info); if (result == -1) { throwIOException(env, "Failed to get abs info for axis (%d)\n", errno); return; } (*env)->CallVoidMethod(env, abs_info_return, abs_info_set, (jint)abs_info.value, (jint)abs_info.minimum, (jint)abs_info.maximum, (jint)abs_info.fuzz, (jint)abs_info.flat); } JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNextEvent(JNIEnv *env, jclass unused, jlong fd_address, jobject linux_event_return) { int fd = (int)fd_address; jclass linux_event_class = (*env)->GetObjectClass(env, linux_event_return); if (linux_event_class == NULL) return JNI_FALSE; jmethodID linux_event_set = (*env)->GetMethodID(env, linux_event_class, "set", "(JJIII)V"); if (linux_event_set == NULL) return JNI_FALSE; struct input_event event; if (read(fd, &event, sizeof(struct input_event)) == -1) { if (errno == EAGAIN) return JNI_FALSE; throwIOException(env, "Failed to read next device event (%d)\n", errno); return JNI_FALSE; } (*env)->CallVoidMethod(env, linux_event_return, linux_event_set, (jlong)event.time.tv_sec, (jlong)event.time.tv_usec, (jint)event.type, (jint)event.code, (jint)event.value); return JNI_TRUE; } JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nUploadRumbleEffect(JNIEnv *env, jclass unused, jlong fd_address, jint id, jint direction, jint trigger_button, jint trigger_interval, jint replay_length, jint replay_delay, jint strong_magnitude, jint weak_magnitude) { int fd = (int)fd_address; struct ff_effect effect; effect.type = FF_RUMBLE; effect.id = id; effect.trigger.button = trigger_button; effect.trigger.interval = trigger_interval; effect.replay.length = replay_length; effect.replay.delay = replay_delay; effect.direction = direction; effect.u.rumble.strong_magnitude = strong_magnitude; effect.u.rumble.weak_magnitude = weak_magnitude; if (ioctl(fd, EVIOCSFF, &effect) == -1) { throwIOException(env, "Failed to upload effect (%d)\n", errno); return -1; } return effect.id; } JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nUploadConstantEffect(JNIEnv *env, jclass unused, jlong fd_address, jint id, jint direction, jint trigger_button, jint trigger_interval, jint replay_length, jint replay_delay, jint constant_level, jint constant_env_attack_length, jint constant_env_attack_level, jint constant_env_fade_length, jint constant_env_fade_level) { int fd = (int)fd_address; struct ff_effect effect; effect.type = FF_CONSTANT; effect.id = id; effect.trigger.button = trigger_button; effect.trigger.interval = trigger_interval; effect.replay.length = replay_length; effect.replay.delay = replay_delay; effect.direction = direction; effect.u.constant.level = constant_level; effect.u.constant.envelope.attack_length = constant_env_attack_length; effect.u.constant.envelope.attack_level = constant_env_attack_level; effect.u.constant.envelope.fade_length = constant_env_fade_length; effect.u.constant.envelope.fade_level = constant_env_fade_level; if (ioctl(fd, EVIOCSFF, &effect) == -1) { throwIOException(env, "Failed to upload effect (%d)\n", errno); return -1; } return effect.id; } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nWriteEvent(JNIEnv *env, jclass unused, jlong fd_address, jint type, jint code, jint value) { int fd = (int)fd_address; struct input_event event; event.type = type; event.code = code; event.value = value; if (write(fd, &event, sizeof(event)) == -1) { throwIOException(env, "Failed to write to device (%d)\n", errno); } } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nEraseEffect(JNIEnv *env, jclass unused, jlong fd_address, jint ff_id) { int fd = (int)fd_address; int ff_id_int = ff_id; if (ioctl(fd, EVIOCRMFF, &ff_id_int) == -1) throwIOException(env, "Failed to erase effect (%d)\n", errno); } jinput-20100502/plugins/linux/src/native/build.xml0000644000175000017500000000412610611652423021735 0ustar twernertwerner jinput-20100502/plugins/linux/src/native/net_java_games_input_LinuxJoystickDevice.c0000644000175000017500000001431410657627417030500 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ #include #include #include #include #include #include #include #include "util.h" #include "net_java_games_input_LinuxJoystickDevice.h" JNIEXPORT jlong JNICALL Java_net_java_games_input_LinuxJoystickDevice_nOpen(JNIEnv *env, jclass unused, jstring path) { const char *path_str = (*env)->GetStringUTFChars(env, path, NULL); if (path_str == NULL) return -1; int fd = open(path_str, O_RDONLY | O_NONBLOCK); if (fd == -1) throwIOException(env, "Failed to open device %s (%d)\n", path_str, errno); (*env)->ReleaseStringUTFChars(env, path, path_str); return fd; } JNIEXPORT void JNICALL Java_net_java_games_input_LinuxJoystickDevice_nClose(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; int result = close(fd); if (result == -1) throwIOException(env, "Failed to close device (%d)\n", errno); } JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetName(JNIEnv *env, jclass unused, jlong fd_address) { #define BUFFER_SIZE 1024 int fd = (int)fd_address; char device_name[BUFFER_SIZE]; if (ioctl(fd, JSIOCGNAME(BUFFER_SIZE), device_name) == -1) { throwIOException(env, "Failed to get device name (%d)\n", errno); return NULL; } jstring jstr = (*env)->NewStringUTF(env, device_name); return jstr; } JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetVersion(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; __u32 version; if (ioctl(fd, JSIOCGVERSION, &version) == -1) { throwIOException(env, "Failed to get device version (%d)\n", errno); return -1; } return version; } JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNumButtons(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; __u8 num_buttons; if (ioctl(fd, JSIOCGBUTTONS, &num_buttons) == -1) { throwIOException(env, "Failed to get number of buttons (%d)\n", errno); return -1; } return num_buttons; } JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNumAxes(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; __u8 num_axes; if (ioctl(fd, JSIOCGAXES, &num_axes) == -1) { throwIOException(env, "Failed to get number of buttons (%d)\n", errno); return -1; } return num_axes; } JNIEXPORT jbyteArray JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetAxisMap(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; __u8 axis_map[ABS_MAX + 1]; if (ioctl(fd, JSIOCGAXMAP, axis_map) == -1) { throwIOException(env, "Failed to get axis map (%d)\n", errno); return NULL; } jbyteArray axis_map_array = (*env)->NewByteArray(env, (ABS_MAX + 1)); if (axis_map_array == NULL) return NULL; (*env)->SetByteArrayRegion(env, axis_map_array, 0, (ABS_MAX + 1), (jbyte *)axis_map); return axis_map_array; } JNIEXPORT jcharArray JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetButtonMap(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; __u16 button_map[KEY_MAX - BTN_MISC + 1]; if (ioctl(fd, JSIOCGBTNMAP, button_map) == -1) { throwIOException(env, "Failed to get button map (%d)\n", errno); return NULL; } jcharArray button_map_array = (*env)->NewCharArray(env, (KEY_MAX - BTN_MISC + 1)); if (button_map_array == NULL) return NULL; (*env)->SetCharArrayRegion(env, button_map_array, 0, (KEY_MAX - BTN_MISC + 1), (jchar *)button_map); return button_map_array; } JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxJoystickDevice_nGetNextEvent(JNIEnv *env, jclass unused, jlong fd_address, jobject event_return) { int fd = (int)fd_address; jclass event_class = (*env)->GetObjectClass(env, event_return); if (event_class == NULL) return JNI_FALSE; jmethodID event_set = (*env)->GetMethodID(env, event_class, "set", "(JIII)V"); if (event_set == NULL) return JNI_FALSE; struct js_event event; if (read(fd, &event, sizeof(event)) == -1) { if (errno == EAGAIN) return JNI_FALSE; throwIOException(env, "Failed to read next device event (%d)\n", errno); return JNI_FALSE; } (*env)->CallVoidMethod(env, event_return, event_set, (jlong)event.time, (jint)event.value, (jint)event.type, (jint)event.number); return JNI_TRUE; } jinput-20100502/plugins/linux/src/java/0000755000175000017500000000000011367367570017563 5ustar twernertwernerjinput-20100502/plugins/linux/src/java/net/0000755000175000017500000000000011367367570020351 5ustar twernertwernerjinput-20100502/plugins/linux/src/java/net/java/0000755000175000017500000000000011367367570021272 5ustar twernertwernerjinput-20100502/plugins/linux/src/java/net/java/games/0000755000175000017500000000000011367367570022366 5ustar twernertwernerjinput-20100502/plugins/linux/src/java/net/java/games/input/0000755000175000017500000000000011367367572023527 5ustar twernertwernerjinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxDeviceTask.java0000644000175000017500000000416210424764262027425 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.io.IOException; abstract class LinuxDeviceTask { public final static int INPROGRESS = 1; public final static int COMPLETED = 2; public final static int FAILED = 3; private Object result; private IOException exception; private int state = INPROGRESS; public final void doExecute() { try { result = execute(); state = COMPLETED; } catch (IOException e) { exception = e; state = FAILED; } } public final IOException getException() { return exception; } public final Object getResult() { return result; } public final int getState() { return state; } protected abstract Object execute() throws IOException; } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxDeviceThread.java0000644000175000017500000000570610424764262027737 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.io.IOException; import java.util.List; import java.util.ArrayList; /** * Linux doesn't have proper support for force feedback * from different threads since it relies on PIDs * to determine ownership of a particular effect slot. * Therefore we have to hack around this by * making sure everything related to FF * (including the final device close that performs * and implicit deletion of all the process' effects) * is run on a single thread. */ final class LinuxDeviceThread extends Thread { private final List tasks = new ArrayList(); public LinuxDeviceThread() { setDaemon(true); start(); } public synchronized final void run() { while (true) { if (!tasks.isEmpty()) { LinuxDeviceTask task = (LinuxDeviceTask)tasks.remove(0); task.doExecute(); synchronized (task) { task.notify(); } } else { try { wait(); } catch (InterruptedException e) { // ignore } } } } public final Object execute(LinuxDeviceTask task) throws IOException { synchronized (this) { tasks.add(task); notify(); } synchronized (task) { while (task.getState() == LinuxDeviceTask.INPROGRESS) { try { task.wait(); } catch (InterruptedException e) { // ignore } } } switch (task.getState()) { case LinuxDeviceTask.COMPLETED: return task.getResult(); case LinuxDeviceTask.FAILED: throw task.getException(); default: throw new RuntimeException("Invalid task state: " + task.getState()); } } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxControllers.java0000644000175000017500000000672710424764262027722 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** helper methods for Linux specific Controllers * @author elias * @version 1.0 */ final class LinuxControllers { private final static LinuxEvent linux_event = new LinuxEvent(); /* Declared synchronized to protect linux_event */ public final static synchronized boolean getNextDeviceEvent(Event event, LinuxEventDevice device) throws IOException { while (device.getNextEvent(linux_event)) { LinuxAxisDescriptor descriptor = linux_event.getDescriptor(); LinuxComponent component = device.mapDescriptor(descriptor); if (component != null) { float value = component.convertValue(linux_event.getValue(), descriptor); event.set(component, value, linux_event.getNanos()); return true; } } return false; } private final static LinuxAbsInfo abs_info = new LinuxAbsInfo(); /* Declared synchronized to protect abs_info */ public final static synchronized float poll(LinuxEventComponent event_component) throws IOException { int native_type = event_component.getDescriptor().getType(); switch (native_type) { case NativeDefinitions.EV_KEY: int native_code = event_component.getDescriptor().getCode(); float state = event_component.getDevice().isKeySet(native_code) ? 1f : 0f; return state; case NativeDefinitions.EV_ABS: event_component.getAbsInfo(abs_info); return abs_info.getValue(); default: throw new RuntimeException("Unkown native_type: " + native_type); } } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java0000644000175000017500000004152111163450763031065 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import net.java.games.util.plugins.Plugin; import java.util.List; import java.util.ArrayList; import java.io.IOException; import java.io.File; import java.io.FilenameFilter; import java.security.AccessController; import java.security.PrivilegedAction; /** Environment plugin for linux * @author elias * @author Jeremy Booth (jeremy@newdawnsoftware.com) */ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plugin { private final static String LIBNAME = "jinput-linux"; private final static String POSTFIX64BIT = "64"; private static boolean supported = false; private final Controller[] controllers; private final List devices = new ArrayList(); private final static LinuxDeviceThread device_thread = new LinuxDeviceThread(); /** * Static utility method for loading native libraries. * It will try to load from either the path given by * the net.java.games.input.librarypath property * or through System.loadLibrary(). * */ static void loadLibrary(final String lib_name) { AccessController.doPrivileged( new PrivilegedAction() { public final Object run() { String lib_path = System.getProperty("net.java.games.input.librarypath"); try { if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); else System.loadLibrary(lib_name); } catch (UnsatisfiedLinkError e) { logln("Failed to load library: " + e.getMessage()); e.printStackTrace(); supported = false; } return null; } }); } static String getPrivilegedProperty(final String property) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property); } }); } static String getPrivilegedProperty(final String property, final String default_value) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return System.getProperty(property, default_value); } }); } static { String osName = getPrivilegedProperty("os.name", "").trim(); if(osName.equals("Linux")) { supported = true; if("i386".equals(getPrivilegedProperty("os.arch"))) { loadLibrary(LIBNAME); } else { loadLibrary(LIBNAME + POSTFIX64BIT); } } } public final static Object execute(LinuxDeviceTask task) throws IOException { return device_thread.execute(task); } public LinuxEnvironmentPlugin() { if(isSupported()) { this.controllers = enumerateControllers(); logln("Linux plugin claims to have found " + controllers.length + " controllers"); AccessController.doPrivileged( new PrivilegedAction() { public final Object run() { Runtime.getRuntime().addShutdownHook(new ShutdownHook()); return null; } }); } else { controllers = new Controller[0]; } } /** Returns a list of all controllers available to this environment, * or an empty array if there are no controllers in this environment. * @return Returns a list of all controllers available to this environment, * or an empty array if there are no controllers in this environment. */ public final Controller[] getControllers() { return controllers; } private final static Component[] createComponents(List event_components, LinuxEventDevice device) { LinuxEventComponent[][] povs = new LinuxEventComponent[4][2]; List components = new ArrayList(); for (int i = 0; i < event_components.size(); i++) { LinuxEventComponent event_component = (LinuxEventComponent)event_components.get(i); Component.Identifier identifier = event_component.getIdentifier(); if (identifier == Component.Identifier.Axis.POV) { int native_code = event_component.getDescriptor().getCode(); switch (native_code) { case NativeDefinitions.ABS_HAT0X: povs[0][0] = event_component; break; case NativeDefinitions.ABS_HAT0Y: povs[0][1] = event_component; break; case NativeDefinitions.ABS_HAT1X: povs[1][0] = event_component; break; case NativeDefinitions.ABS_HAT1Y: povs[1][1] = event_component; break; case NativeDefinitions.ABS_HAT2X: povs[2][0] = event_component; break; case NativeDefinitions.ABS_HAT2Y: povs[2][1] = event_component; break; case NativeDefinitions.ABS_HAT3X: povs[3][0] = event_component; break; case NativeDefinitions.ABS_HAT3Y: povs[3][1] = event_component; break; default: logln("Unknown POV instance: " + native_code); break; } } else if (identifier != null) { LinuxComponent component = new LinuxComponent(event_component); components.add(component); device.registerComponent(event_component.getDescriptor(), component); } } for (int i = 0; i < povs.length; i++) { LinuxEventComponent x = povs[i][0]; LinuxEventComponent y = povs[i][1]; if (x != null && y != null) { LinuxComponent controller_component = new LinuxPOV(x, y); components.add(controller_component); device.registerComponent(x.getDescriptor(), controller_component); device.registerComponent(y.getDescriptor(), controller_component); } } Component[] components_array = new Component[components.size()]; components.toArray(components_array); return components_array; } private final static Mouse createMouseFromDevice(LinuxEventDevice device, Component[] components) throws IOException { Mouse mouse = new LinuxMouse(device, components, new Controller[]{}, device.getRumblers()); if (mouse.getX() != null && mouse.getY() != null && mouse.getPrimaryButton() != null) return mouse; else return null; } private final static Keyboard createKeyboardFromDevice(LinuxEventDevice device, Component[] components) throws IOException { Keyboard keyboard = new LinuxKeyboard(device, components, new Controller[]{}, device.getRumblers()); return keyboard; } private final static Controller createJoystickFromDevice(LinuxEventDevice device, Component[] components, Controller.Type type) throws IOException { Controller joystick = new LinuxAbstractController(device, components, new Controller[]{}, device.getRumblers(), type); return joystick; } private final static Controller createControllerFromDevice(LinuxEventDevice device) throws IOException { List event_components = device.getComponents(); Component[] components = createComponents(event_components, device); Controller.Type type = device.getType(); if (type == Controller.Type.MOUSE) { return createMouseFromDevice(device, components); } else if (type == Controller.Type.KEYBOARD) { return createKeyboardFromDevice(device, components); } else if (type == Controller.Type.STICK || type == Controller.Type.GAMEPAD) { return createJoystickFromDevice(device, components, type); } else return null; } private final Controller[] enumerateControllers() { List controllers = new ArrayList(); List eventControllers = new ArrayList(); List jsControllers = new ArrayList(); enumerateEventControllers(eventControllers); enumerateJoystickControllers(jsControllers); for(int i=0;i= num_keyboard_button_traits) && (num_mouse_button_traits >= num_joystick_button_traits) && (num_mouse_button_traits >= num_gamepad_button_traits)) { mouse_traits++; } else if ((num_keyboard_button_traits >= num_mouse_button_traits) && (num_keyboard_button_traits >= num_joystick_button_traits) && (num_keyboard_button_traits >= num_gamepad_button_traits)) { keyboard_traits++; } else if ((num_joystick_button_traits >= num_keyboard_button_traits) && (num_joystick_button_traits >= num_mouse_button_traits) && (num_joystick_button_traits >= num_gamepad_button_traits)) { joystick_traits++; } else if ((num_gamepad_button_traits >= num_keyboard_button_traits) && (num_gamepad_button_traits >= num_mouse_button_traits) && (num_gamepad_button_traits >= num_joystick_button_traits)) { gamepad_traits++; } if (num_rel_axes >= 2) { mouse_traits++; } if (num_abs_axes >= 2) { joystick_traits++; gamepad_traits++; } if ((mouse_traits >= keyboard_traits) && (mouse_traits >= joystick_traits) && (mouse_traits >= gamepad_traits)) { return Controller.Type.MOUSE; } else if ((keyboard_traits >= mouse_traits) && (keyboard_traits >= joystick_traits) && (keyboard_traits >= gamepad_traits)) { return Controller.Type.KEYBOARD; } else if ((joystick_traits >= mouse_traits) && (joystick_traits >= keyboard_traits) && (joystick_traits >= gamepad_traits)) { return Controller.Type.STICK; } else if ((gamepad_traits >= mouse_traits) && (gamepad_traits >= keyboard_traits) && (gamepad_traits >= joystick_traits)) { return Controller.Type.GAMEPAD; } else return null; } private final Rumbler[] enumerateRumblers() { List rumblers = new ArrayList(); try { int num_effects = getNumEffects(); if (num_effects <= 0) return (Rumbler[])rumblers.toArray(new Rumbler[]{}); byte[] ff_bits = getForceFeedbackBits(); if (isBitSet(ff_bits, NativeDefinitions.FF_RUMBLE) && num_effects > rumblers.size()) { rumblers.add(new LinuxRumbleFF(this)); } } catch (IOException e) { LinuxEnvironmentPlugin.logln("Failed to enumerate rumblers: " + e.getMessage()); } return (Rumbler[])rumblers.toArray(new Rumbler[]{}); } public final Rumbler[] getRumblers() { return rumblers; } public final synchronized int uploadRumbleEffect(int id, int trigger_button, int direction, int trigger_interval, int replay_length, int replay_delay, int strong_magnitude, int weak_magnitude) throws IOException { checkClosed(); return nUploadRumbleEffect(fd, id, direction, trigger_button, trigger_interval, replay_length, replay_delay, strong_magnitude, weak_magnitude); } private final static native int nUploadRumbleEffect(long fd, int id, int direction, int trigger_button, int trigger_interval, int replay_length, int replay_delay, int strong_magnitude, int weak_magnitude) throws IOException; public final synchronized int uploadConstantEffect(int id, int trigger_button, int direction, int trigger_interval, int replay_length, int replay_delay, int constant_level, int constant_env_attack_length, int constant_env_attack_level, int constant_env_fade_length, int constant_env_fade_level) throws IOException { checkClosed(); return nUploadConstantEffect(fd, id, direction, trigger_button, trigger_interval, replay_length, replay_delay, constant_level, constant_env_attack_length, constant_env_attack_level, constant_env_fade_length, constant_env_fade_level); } private final static native int nUploadConstantEffect(long fd, int id, int direction, int trigger_button, int trigger_interval, int replay_length, int replay_delay, int constant_level, int constant_env_attack_length, int constant_env_attack_level, int constant_env_fade_length, int constant_env_fade_level) throws IOException; final void eraseEffect(int id) throws IOException { nEraseEffect(fd, id); } private final static native void nEraseEffect(long fd, int ff_id) throws IOException; public final synchronized void writeEvent(int type, int code, int value) throws IOException { checkClosed(); nWriteEvent(fd, type, code, value); } private final static native void nWriteEvent(long fd, int type, int code, int value) throws IOException; public final void registerComponent(LinuxAxisDescriptor desc, LinuxComponent component) { component_map.put(desc, component); } public final LinuxComponent mapDescriptor(LinuxAxisDescriptor desc) { return (LinuxComponent)component_map.get(desc); } public final Controller.PortType getPortType() throws IOException { return input_id.getPortType(); } public final LinuxInputID getInputID() { return input_id; } private final LinuxInputID getDeviceInputID() throws IOException { return nGetInputID(fd); } private final static native LinuxInputID nGetInputID(long fd) throws IOException; public final int getNumEffects() throws IOException { return nGetNumEffects(fd); } private final static native int nGetNumEffects(long fd) throws IOException; private final int getVersion() throws IOException { return nGetVersion(fd); } private final static native int nGetVersion(long fd) throws IOException; public final synchronized boolean getNextEvent(LinuxEvent linux_event) throws IOException { checkClosed(); return nGetNextEvent(fd, linux_event); } private final static native boolean nGetNextEvent(long fd, LinuxEvent linux_event) throws IOException; public final synchronized void getAbsInfo(int abs_axis, LinuxAbsInfo abs_info) throws IOException { checkClosed(); nGetAbsInfo(fd, abs_axis, abs_info); } private final static native void nGetAbsInfo(long fd, int abs_axis, LinuxAbsInfo abs_info) throws IOException; private final void addKeys(List components) throws IOException { byte[] bits = getKeysBits(); for (int i = 0; i < bits.length*8; i++) { if (isBitSet(bits, i)) { Component.Identifier id = LinuxNativeTypesMap.getButtonID(i); components.add(new LinuxEventComponent(this, id, false, NativeDefinitions.EV_KEY, i)); } } } private final void addAbsoluteAxes(List components) throws IOException { byte[] bits = getAbsoluteAxesBits(); for (int i = 0; i < bits.length*8; i++) { if (isBitSet(bits, i)) { Component.Identifier id = LinuxNativeTypesMap.getAbsAxisID(i); components.add(new LinuxEventComponent(this, id, false, NativeDefinitions.EV_ABS, i)); } } } private final void addRelativeAxes(List components) throws IOException { byte[] bits = getRelativeAxesBits(); for (int i = 0; i < bits.length*8; i++) { if (isBitSet(bits, i)) { Component.Identifier id = LinuxNativeTypesMap.getRelAxisID(i); components.add(new LinuxEventComponent(this, id, true, NativeDefinitions.EV_REL, i)); } } } public final List getComponents() { return components; } private final List getDeviceComponents() throws IOException { List components = new ArrayList(); byte[] evtype_bits = getEventTypeBits(); if (isBitSet(evtype_bits, NativeDefinitions.EV_KEY)) addKeys(components); if (isBitSet(evtype_bits, NativeDefinitions.EV_ABS)) addAbsoluteAxes(components); if (isBitSet(evtype_bits, NativeDefinitions.EV_REL)) addRelativeAxes(components); return components; } private final byte[] getForceFeedbackBits() throws IOException { byte[] bits = new byte[NativeDefinitions.FF_MAX/8 + 1]; nGetBits(fd, NativeDefinitions.EV_FF, bits); return bits; } private final byte[] getKeysBits() throws IOException { byte[] bits = new byte[NativeDefinitions.KEY_MAX/8 + 1]; nGetBits(fd, NativeDefinitions.EV_KEY, bits); return bits; } private final byte[] getAbsoluteAxesBits() throws IOException { byte[] bits = new byte[NativeDefinitions.ABS_MAX/8 + 1]; nGetBits(fd, NativeDefinitions.EV_ABS, bits); return bits; } private final byte[] getRelativeAxesBits() throws IOException { byte[] bits = new byte[NativeDefinitions.REL_MAX/8 + 1]; nGetBits(fd, NativeDefinitions.EV_REL, bits); return bits; } private final byte[] getEventTypeBits() throws IOException { byte[] bits = new byte[NativeDefinitions.EV_MAX/8 + 1]; nGetBits(fd, 0, bits); return bits; } private final static native void nGetBits(long fd, int ev_type, byte[] evtype_bits) throws IOException; private final byte[] getDeviceUsageBits() throws IOException { byte[] bits = new byte[NativeDefinitions.USAGE_MAX/8 + 1]; if (getVersion() >= 0x010001) { nGetDeviceUsageBits(fd, bits); } return bits; } private final static native void nGetDeviceUsageBits(long fd, byte[] type_bits) throws IOException; public final synchronized void pollKeyStates() throws IOException { nGetKeyStates(fd, key_states); } private final static native void nGetKeyStates(long fd, byte[] states) throws IOException; public final boolean isKeySet(int bit) { return isBitSet(key_states, bit); } public final static boolean isBitSet(byte[] bits, int bit) { return (bits[bit/8] & (1<<(bit%8))) != 0; } public final String getName() { return name; } private final String getDeviceName() throws IOException { return nGetName(fd); } private final static native String nGetName(long fd) throws IOException; public synchronized final void close() throws IOException { if (closed) return; closed = true; LinuxEnvironmentPlugin.execute(new LinuxDeviceTask() { protected final Object execute() throws IOException { nClose(fd); return null; } }); } private final static native void nClose(long fd) throws IOException; private final void checkClosed() throws IOException { if (closed) throw new IOException("Device is closed"); } protected void finalize() throws IOException { close(); } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxAbstractController.java0000644000175000017500000000562710424764261031220 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents a Linux controller * @author elias * @version 1.0 */ final class LinuxAbstractController extends AbstractController { private final PortType port; private final LinuxEventDevice device; private final Type type; protected LinuxAbstractController(LinuxEventDevice device, Component[] components, Controller[] children, Rumbler[] rumblers, Type type) throws IOException { super(device.getName(), components, children, rumblers); this.device = device; this.port = device.getPortType(); this.type = type; } public final PortType getPortType() { return port; } public final void pollDevice() throws IOException { device.pollKeyStates(); } protected final boolean getNextDeviceEvent(Event event) throws IOException { return LinuxControllers.getNextDeviceEvent(event, device); } public Type getType() { return type; } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxPOV.java0000644000175000017500000000716710633011276026047 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents a linux button * @author elias * @version 1.0 */ final class LinuxPOV extends LinuxComponent { private final LinuxEventComponent component_x; private final LinuxEventComponent component_y; private float last_x; private float last_y; public LinuxPOV(LinuxEventComponent component_x, LinuxEventComponent component_y) { super(component_x); this.component_x = component_x; this.component_y = component_y; } protected final float poll() throws IOException { last_x = LinuxControllers.poll(component_x); last_y = LinuxControllers.poll(component_y); return convertValue(0f, null); } public float convertValue(float value, LinuxAxisDescriptor descriptor) { if (descriptor == component_x.getDescriptor()) last_x = value; if (descriptor == component_y.getDescriptor()) last_y = value; if (last_x == -1 && last_y == -1) return Component.POV.UP_LEFT; else if (last_x == -1 && last_y == 0) return Component.POV.LEFT; else if (last_x == -1 && last_y == 1) return Component.POV.DOWN_LEFT; else if (last_x == 0 && last_y == -1) return Component.POV.UP; else if (last_x == 0 && last_y == 0) return Component.POV.OFF; else if (last_x == 0 && last_y == 1) return Component.POV.DOWN; else if (last_x == 1 && last_y == -1) return Component.POV.UP_RIGHT; else if (last_x == 1 && last_y == 0) return Component.POV.RIGHT; else if (last_x == 1 && last_y == 1) return Component.POV.DOWN_RIGHT; else { LinuxEnvironmentPlugin.logln("Unknown values x = " + last_x + " | y = " + last_y); return Component.POV.OFF; } } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxInputID.java0000644000175000017500000000424610424764264026724 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; /** * @author elias */ final class LinuxInputID { private final int bustype; private final int vendor; private final int product; private final int version; public LinuxInputID(int bustype, int vendor, int product, int version) { this.bustype = bustype; this.vendor = vendor; this.product = product; this.version = version; } public final Controller.PortType getPortType() { return LinuxNativeTypesMap.getPortType(bustype); } public final String toString() { return "LinuxInputID: bustype = 0x" + Integer.toHexString(bustype) + " | vendor = 0x" + Integer.toHexString(vendor) + " | product = 0x" + Integer.toHexString(product) + " | version = 0x" + Integer.toHexString(version); } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxComponent.java0000644000175000017500000000563210424764262027350 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents a linux Axis * @author elias * @version 1.0 */ class LinuxComponent extends AbstractComponent { private final LinuxEventComponent component; public LinuxComponent(LinuxEventComponent component) { super(component.getIdentifier().getName(), component.getIdentifier()); this.component = component; } public final boolean isRelative() { return component.isRelative(); } public final boolean isAnalog() { return component.isAnalog(); } protected float poll() throws IOException { return convertValue(LinuxControllers.poll(component), component.getDescriptor()); } float convertValue(float value, LinuxAxisDescriptor descriptor) { return getComponent().convertValue(value); } public final float getDeadZone() { return component.getDeadZone(); } public final LinuxEventComponent getComponent() { return component; } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxNativeTypesMap.java0000644000175000017500000011714611273015702030312 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.util.logging.Logger; /** * Mapping utility class between native type ints and string names or * Key.Identifiers * @author Jeremy Booth (jeremy@newdawnsoftware.com) */ class LinuxNativeTypesMap { private static LinuxNativeTypesMap INSTANCE = new LinuxNativeTypesMap(); private static Logger log = Logger.getLogger(LinuxNativeTypesMap.class.getName()); private final Component.Identifier relAxesIDs[]; private final Component.Identifier absAxesIDs[]; private final Component.Identifier buttonIDs[]; /** create an empty, uninitialsed map */ private LinuxNativeTypesMap() { buttonIDs = new Component.Identifier[NativeDefinitions.KEY_MAX]; relAxesIDs = new Component.Identifier[NativeDefinitions.REL_MAX]; absAxesIDs = new Component.Identifier[NativeDefinitions.ABS_MAX]; reInit(); } /** Do the work. */ private void reInit() { buttonIDs[NativeDefinitions.KEY_ESC] = Component.Identifier.Key.ESCAPE; buttonIDs[NativeDefinitions.KEY_1] = Component.Identifier.Key._1; buttonIDs[NativeDefinitions.KEY_2] = Component.Identifier.Key._2; buttonIDs[NativeDefinitions.KEY_3] = Component.Identifier.Key._3; buttonIDs[NativeDefinitions.KEY_4] = Component.Identifier.Key._4; buttonIDs[NativeDefinitions.KEY_5] = Component.Identifier.Key._5; buttonIDs[NativeDefinitions.KEY_6] = Component.Identifier.Key._6; buttonIDs[NativeDefinitions.KEY_7] = Component.Identifier.Key._7; buttonIDs[NativeDefinitions.KEY_8] = Component.Identifier.Key._8; buttonIDs[NativeDefinitions.KEY_9] = Component.Identifier.Key._9; buttonIDs[NativeDefinitions.KEY_0] = Component.Identifier.Key._0; buttonIDs[NativeDefinitions.KEY_MINUS] = Component.Identifier.Key.MINUS; buttonIDs[NativeDefinitions.KEY_EQUAL] = Component.Identifier.Key.EQUALS; buttonIDs[NativeDefinitions.KEY_BACKSPACE] = Component.Identifier.Key.BACK; buttonIDs[NativeDefinitions.KEY_TAB] = Component.Identifier.Key.TAB; buttonIDs[NativeDefinitions.KEY_Q] = Component.Identifier.Key.Q; buttonIDs[NativeDefinitions.KEY_W] = Component.Identifier.Key.W; buttonIDs[NativeDefinitions.KEY_E] = Component.Identifier.Key.E; buttonIDs[NativeDefinitions.KEY_R] = Component.Identifier.Key.R; buttonIDs[NativeDefinitions.KEY_T] = Component.Identifier.Key.T; buttonIDs[NativeDefinitions.KEY_Y] = Component.Identifier.Key.Y; buttonIDs[NativeDefinitions.KEY_U] = Component.Identifier.Key.U; buttonIDs[NativeDefinitions.KEY_I] = Component.Identifier.Key.I; buttonIDs[NativeDefinitions.KEY_O] = Component.Identifier.Key.O; buttonIDs[NativeDefinitions.KEY_P] = Component.Identifier.Key.P; buttonIDs[NativeDefinitions.KEY_LEFTBRACE] = Component.Identifier.Key.LBRACKET; buttonIDs[NativeDefinitions.KEY_RIGHTBRACE] = Component.Identifier.Key.RBRACKET; buttonIDs[NativeDefinitions.KEY_ENTER] = Component.Identifier.Key.RETURN; buttonIDs[NativeDefinitions.KEY_LEFTCTRL] = Component.Identifier.Key.LCONTROL; buttonIDs[NativeDefinitions.KEY_A] = Component.Identifier.Key.A; buttonIDs[NativeDefinitions.KEY_S] = Component.Identifier.Key.S; buttonIDs[NativeDefinitions.KEY_D] = Component.Identifier.Key.D; buttonIDs[NativeDefinitions.KEY_F] = Component.Identifier.Key.F; buttonIDs[NativeDefinitions.KEY_G] = Component.Identifier.Key.G; buttonIDs[NativeDefinitions.KEY_H] = Component.Identifier.Key.H; buttonIDs[NativeDefinitions.KEY_J] = Component.Identifier.Key.J; buttonIDs[NativeDefinitions.KEY_K] = Component.Identifier.Key.K; buttonIDs[NativeDefinitions.KEY_L] = Component.Identifier.Key.L; buttonIDs[NativeDefinitions.KEY_SEMICOLON] = Component.Identifier.Key.SEMICOLON; buttonIDs[NativeDefinitions.KEY_APOSTROPHE] = Component.Identifier.Key.APOSTROPHE; buttonIDs[NativeDefinitions.KEY_GRAVE] = Component.Identifier.Key.GRAVE; buttonIDs[NativeDefinitions.KEY_LEFTSHIFT] = Component.Identifier.Key.LSHIFT; buttonIDs[NativeDefinitions.KEY_BACKSLASH] = Component.Identifier.Key.BACKSLASH; buttonIDs[NativeDefinitions.KEY_Z] = Component.Identifier.Key.Z; buttonIDs[NativeDefinitions.KEY_X] = Component.Identifier.Key.X; buttonIDs[NativeDefinitions.KEY_C] = Component.Identifier.Key.C; buttonIDs[NativeDefinitions.KEY_V] = Component.Identifier.Key.V; buttonIDs[NativeDefinitions.KEY_B] = Component.Identifier.Key.B; buttonIDs[NativeDefinitions.KEY_N] = Component.Identifier.Key.N; buttonIDs[NativeDefinitions.KEY_M] = Component.Identifier.Key.M; buttonIDs[NativeDefinitions.KEY_COMMA] = Component.Identifier.Key.COMMA; buttonIDs[NativeDefinitions.KEY_DOT] = Component.Identifier.Key.PERIOD; buttonIDs[NativeDefinitions.KEY_SLASH] = Component.Identifier.Key.SLASH; buttonIDs[NativeDefinitions.KEY_RIGHTSHIFT] = Component.Identifier.Key.RSHIFT; buttonIDs[NativeDefinitions.KEY_KPASTERISK] = Component.Identifier.Key.MULTIPLY; buttonIDs[NativeDefinitions.KEY_LEFTALT] = Component.Identifier.Key.LALT; buttonIDs[NativeDefinitions.KEY_SPACE] = Component.Identifier.Key.SPACE; buttonIDs[NativeDefinitions.KEY_CAPSLOCK] = Component.Identifier.Key.CAPITAL; buttonIDs[NativeDefinitions.KEY_F1] = Component.Identifier.Key.F1; buttonIDs[NativeDefinitions.KEY_F2] = Component.Identifier.Key.F2; buttonIDs[NativeDefinitions.KEY_F3] = Component.Identifier.Key.F3; buttonIDs[NativeDefinitions.KEY_F4] = Component.Identifier.Key.F4; buttonIDs[NativeDefinitions.KEY_F5] = Component.Identifier.Key.F5; buttonIDs[NativeDefinitions.KEY_F6] = Component.Identifier.Key.F6; buttonIDs[NativeDefinitions.KEY_F7] = Component.Identifier.Key.F7; buttonIDs[NativeDefinitions.KEY_F8] = Component.Identifier.Key.F8; buttonIDs[NativeDefinitions.KEY_F9] = Component.Identifier.Key.F9; buttonIDs[NativeDefinitions.KEY_F10] = Component.Identifier.Key.F10; buttonIDs[NativeDefinitions.KEY_NUMLOCK] = Component.Identifier.Key.NUMLOCK; buttonIDs[NativeDefinitions.KEY_SCROLLLOCK] = Component.Identifier.Key.SCROLL; buttonIDs[NativeDefinitions.KEY_KP7] = Component.Identifier.Key.NUMPAD7; buttonIDs[NativeDefinitions.KEY_KP8] = Component.Identifier.Key.NUMPAD8; buttonIDs[NativeDefinitions.KEY_KP9] = Component.Identifier.Key.NUMPAD9; buttonIDs[NativeDefinitions.KEY_KPMINUS] = Component.Identifier.Key.SUBTRACT; buttonIDs[NativeDefinitions.KEY_KP4] = Component.Identifier.Key.NUMPAD4; buttonIDs[NativeDefinitions.KEY_KP5] = Component.Identifier.Key.NUMPAD5; buttonIDs[NativeDefinitions.KEY_KP6] = Component.Identifier.Key.NUMPAD6; buttonIDs[NativeDefinitions.KEY_KPPLUS] = Component.Identifier.Key.ADD; buttonIDs[NativeDefinitions.KEY_KP1] = Component.Identifier.Key.NUMPAD1; buttonIDs[NativeDefinitions.KEY_KP2] = Component.Identifier.Key.NUMPAD2; buttonIDs[NativeDefinitions.KEY_KP3] = Component.Identifier.Key.NUMPAD3; buttonIDs[NativeDefinitions.KEY_KP0] = Component.Identifier.Key.NUMPAD0; buttonIDs[NativeDefinitions.KEY_KPDOT] = Component.Identifier.Key.DECIMAL; // buttonIDs[NativeDefinitions.KEY_103RD] = null; buttonIDs[NativeDefinitions.KEY_F13] = Component.Identifier.Key.F13; buttonIDs[NativeDefinitions.KEY_102ND] = null; buttonIDs[NativeDefinitions.KEY_F11] = Component.Identifier.Key.F11; buttonIDs[NativeDefinitions.KEY_F12] = Component.Identifier.Key.F12; buttonIDs[NativeDefinitions.KEY_F14] = Component.Identifier.Key.F14; buttonIDs[NativeDefinitions.KEY_F15] = Component.Identifier.Key.F15; buttonIDs[NativeDefinitions.KEY_F16] = null; buttonIDs[NativeDefinitions.KEY_F17] = null; buttonIDs[NativeDefinitions.KEY_F18] = null; buttonIDs[NativeDefinitions.KEY_F19] = null; buttonIDs[NativeDefinitions.KEY_F20] = null; buttonIDs[NativeDefinitions.KEY_KPENTER] = Component.Identifier.Key.NUMPADENTER; buttonIDs[NativeDefinitions.KEY_RIGHTCTRL] = Component.Identifier.Key.RCONTROL; buttonIDs[NativeDefinitions.KEY_KPSLASH] = Component.Identifier.Key.DIVIDE; buttonIDs[NativeDefinitions.KEY_SYSRQ] = Component.Identifier.Key.SYSRQ; buttonIDs[NativeDefinitions.KEY_RIGHTALT] = Component.Identifier.Key.RALT; buttonIDs[NativeDefinitions.KEY_LINEFEED] = null; buttonIDs[NativeDefinitions.KEY_HOME] = Component.Identifier.Key.HOME; buttonIDs[NativeDefinitions.KEY_UP] = Component.Identifier.Key.UP; buttonIDs[NativeDefinitions.KEY_PAGEUP] = Component.Identifier.Key.PAGEUP; buttonIDs[NativeDefinitions.KEY_LEFT] = Component.Identifier.Key.LEFT; buttonIDs[NativeDefinitions.KEY_RIGHT] = Component.Identifier.Key.RIGHT; buttonIDs[NativeDefinitions.KEY_END] = Component.Identifier.Key.END; buttonIDs[NativeDefinitions.KEY_DOWN] = Component.Identifier.Key.DOWN; buttonIDs[NativeDefinitions.KEY_PAGEDOWN] = Component.Identifier.Key.PAGEDOWN; buttonIDs[NativeDefinitions.KEY_INSERT] = Component.Identifier.Key.INSERT; buttonIDs[NativeDefinitions.KEY_DELETE] = Component.Identifier.Key.DELETE; buttonIDs[NativeDefinitions.KEY_PAUSE] = Component.Identifier.Key.PAUSE; /* buttonIDs[NativeDefinitions.KEY_MACRO] = "Macro"; buttonIDs[NativeDefinitions.KEY_MUTE] = "Mute"; buttonIDs[NativeDefinitions.KEY_VOLUMEDOWN] = "Volume Down"; buttonIDs[NativeDefinitions.KEY_VOLUMEUP] = "Volume Up"; buttonIDs[NativeDefinitions.KEY_POWER] = "Power";*/ buttonIDs[NativeDefinitions.KEY_KPEQUAL] = Component.Identifier.Key.NUMPADEQUAL; //buttonIDs[NativeDefinitions.KEY_KPPLUSMINUS] = "KeyPad +/-"; /* buttonIDs[NativeDefinitions.KEY_F21] = "F21"; buttonIDs[NativeDefinitions.KEY_F22] = "F22"; buttonIDs[NativeDefinitions.KEY_F23] = "F23"; buttonIDs[NativeDefinitions.KEY_F24] = "F24"; buttonIDs[NativeDefinitions.KEY_KPCOMMA] = "KeyPad comma"; buttonIDs[NativeDefinitions.KEY_LEFTMETA] = "LH Meta"; buttonIDs[NativeDefinitions.KEY_RIGHTMETA] = "RH Meta"; buttonIDs[NativeDefinitions.KEY_COMPOSE] = "Compose"; buttonIDs[NativeDefinitions.KEY_STOP] = "Stop"; buttonIDs[NativeDefinitions.KEY_AGAIN] = "Again"; buttonIDs[NativeDefinitions.KEY_PROPS] = "Properties"; buttonIDs[NativeDefinitions.KEY_UNDO] = "Undo"; buttonIDs[NativeDefinitions.KEY_FRONT] = "Front"; buttonIDs[NativeDefinitions.KEY_COPY] = "Copy"; buttonIDs[NativeDefinitions.KEY_OPEN] = "Open"; buttonIDs[NativeDefinitions.KEY_PASTE] = "Paste"; buttonIDs[NativeDefinitions.KEY_FIND] = "Find"; buttonIDs[NativeDefinitions.KEY_CUT] = "Cut"; buttonIDs[NativeDefinitions.KEY_HELP] = "Help"; buttonIDs[NativeDefinitions.KEY_MENU] = "Menu"; buttonIDs[NativeDefinitions.KEY_CALC] = "Calculator"; buttonIDs[NativeDefinitions.KEY_SETUP] = "Setup";*/ buttonIDs[NativeDefinitions.KEY_SLEEP] = Component.Identifier.Key.SLEEP; /*buttonIDs[NativeDefinitions.KEY_WAKEUP] = "Wakeup"; buttonIDs[NativeDefinitions.KEY_FILE] = "File"; buttonIDs[NativeDefinitions.KEY_SENDFILE] = "Send File"; buttonIDs[NativeDefinitions.KEY_DELETEFILE] = "Delete File"; buttonIDs[NativeDefinitions.KEY_XFER] = "Transfer"; buttonIDs[NativeDefinitions.KEY_PROG1] = "Program 1"; buttonIDs[NativeDefinitions.KEY_PROG2] = "Program 2"; buttonIDs[NativeDefinitions.KEY_WWW] = "Web Browser"; buttonIDs[NativeDefinitions.KEY_MSDOS] = "DOS mode"; buttonIDs[NativeDefinitions.KEY_COFFEE] = "Coffee"; buttonIDs[NativeDefinitions.KEY_DIRECTION] = "Direction"; buttonIDs[NativeDefinitions.KEY_CYCLEWINDOWS] = "Window cycle"; buttonIDs[NativeDefinitions.KEY_MAIL] = "Mail"; buttonIDs[NativeDefinitions.KEY_BOOKMARKS] = "Book Marks"; buttonIDs[NativeDefinitions.KEY_COMPUTER] = "Computer"; buttonIDs[NativeDefinitions.KEY_BACK] = "Back"; buttonIDs[NativeDefinitions.KEY_FORWARD] = "Forward"; buttonIDs[NativeDefinitions.KEY_CLOSECD] = "Close CD"; buttonIDs[NativeDefinitions.KEY_EJECTCD] = "Eject CD"; buttonIDs[NativeDefinitions.KEY_EJECTCLOSECD] = "Eject / Close CD"; buttonIDs[NativeDefinitions.KEY_NEXTSONG] = "Next Song"; buttonIDs[NativeDefinitions.KEY_PLAYPAUSE] = "Play and Pause"; buttonIDs[NativeDefinitions.KEY_PREVIOUSSONG] = "Previous Song"; buttonIDs[NativeDefinitions.KEY_STOPCD] = "Stop CD"; buttonIDs[NativeDefinitions.KEY_RECORD] = "Record"; buttonIDs[NativeDefinitions.KEY_REWIND] = "Rewind"; buttonIDs[NativeDefinitions.KEY_PHONE] = "Phone"; buttonIDs[NativeDefinitions.KEY_ISO] = "ISO"; buttonIDs[NativeDefinitions.KEY_CONFIG] = "Config"; buttonIDs[NativeDefinitions.KEY_HOMEPAGE] = "Home"; buttonIDs[NativeDefinitions.KEY_REFRESH] = "Refresh"; buttonIDs[NativeDefinitions.KEY_EXIT] = "Exit"; buttonIDs[NativeDefinitions.KEY_MOVE] = "Move"; buttonIDs[NativeDefinitions.KEY_EDIT] = "Edit"; buttonIDs[NativeDefinitions.KEY_SCROLLUP] = "Scroll Up"; buttonIDs[NativeDefinitions.KEY_SCROLLDOWN] = "Scroll Down"; buttonIDs[NativeDefinitions.KEY_KPLEFTPAREN] = "KeyPad LH parenthesis"; buttonIDs[NativeDefinitions.KEY_KPRIGHTPAREN] = "KeyPad RH parenthesis"; buttonIDs[NativeDefinitions.KEY_INTL1] = "Intl 1"; buttonIDs[NativeDefinitions.KEY_INTL2] = "Intl 2"; buttonIDs[NativeDefinitions.KEY_INTL3] = "Intl 3"; buttonIDs[NativeDefinitions.KEY_INTL4] = "Intl 4"; buttonIDs[NativeDefinitions.KEY_INTL5] = "Intl 5"; buttonIDs[NativeDefinitions.KEY_INTL6] = "Intl 6"; buttonIDs[NativeDefinitions.KEY_INTL7] = "Intl 7"; buttonIDs[NativeDefinitions.KEY_INTL8] = "Intl 8"; buttonIDs[NativeDefinitions.KEY_INTL9] = "Intl 9"; buttonIDs[NativeDefinitions.KEY_LANG1] = "Language 1"; buttonIDs[NativeDefinitions.KEY_LANG2] = "Language 2"; buttonIDs[NativeDefinitions.KEY_LANG3] = "Language 3"; buttonIDs[NativeDefinitions.KEY_LANG4] = "Language 4"; buttonIDs[NativeDefinitions.KEY_LANG5] = "Language 5"; buttonIDs[NativeDefinitions.KEY_LANG6] = "Language 6"; buttonIDs[NativeDefinitions.KEY_LANG7] = "Language 7"; buttonIDs[NativeDefinitions.KEY_LANG8] = "Language 8"; buttonIDs[NativeDefinitions.KEY_LANG9] = "Language 9"; buttonIDs[NativeDefinitions.KEY_PLAYCD] = "Play CD"; buttonIDs[NativeDefinitions.KEY_PAUSECD] = "Pause CD"; buttonIDs[NativeDefinitions.KEY_PROG3] = "Program 3"; buttonIDs[NativeDefinitions.KEY_PROG4] = "Program 4"; buttonIDs[NativeDefinitions.KEY_SUSPEND] = "Suspend"; buttonIDs[NativeDefinitions.KEY_CLOSE] = "Close";*/ buttonIDs[NativeDefinitions.KEY_UNKNOWN] = Component.Identifier.Key.UNLABELED; /*buttonIDs[NativeDefinitions.KEY_BRIGHTNESSDOWN] = "Brightness Down"; buttonIDs[NativeDefinitions.KEY_BRIGHTNESSUP] = "Brightness Up";*/ //Misc keys buttonIDs[NativeDefinitions.BTN_0] = Component.Identifier.Button._0; buttonIDs[NativeDefinitions.BTN_1] = Component.Identifier.Button._1; buttonIDs[NativeDefinitions.BTN_2] = Component.Identifier.Button._2; buttonIDs[NativeDefinitions.BTN_3] = Component.Identifier.Button._3; buttonIDs[NativeDefinitions.BTN_4] = Component.Identifier.Button._4; buttonIDs[NativeDefinitions.BTN_5] = Component.Identifier.Button._5; buttonIDs[NativeDefinitions.BTN_6] = Component.Identifier.Button._6; buttonIDs[NativeDefinitions.BTN_7] = Component.Identifier.Button._7; buttonIDs[NativeDefinitions.BTN_8] = Component.Identifier.Button._8; buttonIDs[NativeDefinitions.BTN_9] = Component.Identifier.Button._9; // Mouse buttonIDs[NativeDefinitions.BTN_LEFT] = Component.Identifier.Button.LEFT; buttonIDs[NativeDefinitions.BTN_RIGHT] = Component.Identifier.Button.RIGHT; buttonIDs[NativeDefinitions.BTN_MIDDLE] = Component.Identifier.Button.MIDDLE; buttonIDs[NativeDefinitions.BTN_SIDE] = Component.Identifier.Button.SIDE; buttonIDs[NativeDefinitions.BTN_EXTRA] = Component.Identifier.Button.EXTRA; buttonIDs[NativeDefinitions.BTN_FORWARD] = Component.Identifier.Button.FORWARD; buttonIDs[NativeDefinitions.BTN_BACK] = Component.Identifier.Button.BACK; // Joystick buttonIDs[NativeDefinitions.BTN_TRIGGER] = Component.Identifier.Button.TRIGGER; buttonIDs[NativeDefinitions.BTN_THUMB] = Component.Identifier.Button.THUMB; buttonIDs[NativeDefinitions.BTN_THUMB2] = Component.Identifier.Button.THUMB2; buttonIDs[NativeDefinitions.BTN_TOP] = Component.Identifier.Button.TOP; buttonIDs[NativeDefinitions.BTN_TOP2] = Component.Identifier.Button.TOP2; buttonIDs[NativeDefinitions.BTN_PINKIE] = Component.Identifier.Button.PINKIE; buttonIDs[NativeDefinitions.BTN_BASE] = Component.Identifier.Button.BASE; buttonIDs[NativeDefinitions.BTN_BASE2] = Component.Identifier.Button.BASE2; buttonIDs[NativeDefinitions.BTN_BASE3] = Component.Identifier.Button.BASE3; buttonIDs[NativeDefinitions.BTN_BASE4] = Component.Identifier.Button.BASE4; buttonIDs[NativeDefinitions.BTN_BASE5] = Component.Identifier.Button.BASE5; buttonIDs[NativeDefinitions.BTN_BASE6] = Component.Identifier.Button.BASE6; buttonIDs[NativeDefinitions.BTN_DEAD] = Component.Identifier.Button.DEAD; // Gamepad buttonIDs[NativeDefinitions.BTN_A] = Component.Identifier.Button.A; buttonIDs[NativeDefinitions.BTN_B] = Component.Identifier.Button.B; buttonIDs[NativeDefinitions.BTN_C] = Component.Identifier.Button.C; buttonIDs[NativeDefinitions.BTN_X] = Component.Identifier.Button.X; buttonIDs[NativeDefinitions.BTN_Y] = Component.Identifier.Button.Y; buttonIDs[NativeDefinitions.BTN_Z] = Component.Identifier.Button.Z; buttonIDs[NativeDefinitions.BTN_TL] = Component.Identifier.Button.LEFT_THUMB; buttonIDs[NativeDefinitions.BTN_TR] = Component.Identifier.Button.RIGHT_THUMB; buttonIDs[NativeDefinitions.BTN_TL2] = Component.Identifier.Button.LEFT_THUMB2; buttonIDs[NativeDefinitions.BTN_TR2] = Component.Identifier.Button.RIGHT_THUMB2; buttonIDs[NativeDefinitions.BTN_SELECT] = Component.Identifier.Button.SELECT; buttonIDs[NativeDefinitions.BTN_MODE] = Component.Identifier.Button.MODE; buttonIDs[NativeDefinitions.BTN_THUMBL] = Component.Identifier.Button.LEFT_THUMB3; buttonIDs[NativeDefinitions.BTN_THUMBR] = Component.Identifier.Button.RIGHT_THUMB3; // Digitiser buttonIDs[NativeDefinitions.BTN_TOOL_PEN] = Component.Identifier.Button.TOOL_PEN; buttonIDs[NativeDefinitions.BTN_TOOL_RUBBER] = Component.Identifier.Button.TOOL_RUBBER; buttonIDs[NativeDefinitions.BTN_TOOL_BRUSH] = Component.Identifier.Button.TOOL_BRUSH; buttonIDs[NativeDefinitions.BTN_TOOL_PENCIL] = Component.Identifier.Button.TOOL_PENCIL; buttonIDs[NativeDefinitions.BTN_TOOL_AIRBRUSH] = Component.Identifier.Button.TOOL_AIRBRUSH; buttonIDs[NativeDefinitions.BTN_TOOL_FINGER] = Component.Identifier.Button.TOOL_FINGER; buttonIDs[NativeDefinitions.BTN_TOOL_MOUSE] = Component.Identifier.Button.TOOL_MOUSE; buttonIDs[NativeDefinitions.BTN_TOOL_LENS] = Component.Identifier.Button.TOOL_LENS; buttonIDs[NativeDefinitions.BTN_TOUCH] = Component.Identifier.Button.TOUCH; buttonIDs[NativeDefinitions.BTN_STYLUS] = Component.Identifier.Button.STYLUS; buttonIDs[NativeDefinitions.BTN_STYLUS2] = Component.Identifier.Button.STYLUS2; relAxesIDs[NativeDefinitions.REL_X] = Component.Identifier.Axis.X; relAxesIDs[NativeDefinitions.REL_Y] = Component.Identifier.Axis.Y; relAxesIDs[NativeDefinitions.REL_Z] = Component.Identifier.Axis.Z; relAxesIDs[NativeDefinitions.REL_WHEEL] = Component.Identifier.Axis.Z; // There are guesses as I have no idea what they would be used for relAxesIDs[NativeDefinitions.REL_HWHEEL] = Component.Identifier.Axis.SLIDER; relAxesIDs[NativeDefinitions.REL_DIAL] = Component.Identifier.Axis.SLIDER; relAxesIDs[NativeDefinitions.REL_MISC] = Component.Identifier.Axis.SLIDER; absAxesIDs[NativeDefinitions.ABS_X] = Component.Identifier.Axis.X; absAxesIDs[NativeDefinitions.ABS_Y] = Component.Identifier.Axis.Y; absAxesIDs[NativeDefinitions.ABS_Z] = Component.Identifier.Axis.Z; absAxesIDs[NativeDefinitions.ABS_RX] = Component.Identifier.Axis.RX; absAxesIDs[NativeDefinitions.ABS_RY] = Component.Identifier.Axis.RY; absAxesIDs[NativeDefinitions.ABS_RZ] = Component.Identifier.Axis.RZ; absAxesIDs[NativeDefinitions.ABS_THROTTLE] = Component.Identifier.Axis.SLIDER; absAxesIDs[NativeDefinitions.ABS_RUDDER] = Component.Identifier.Axis.RZ; absAxesIDs[NativeDefinitions.ABS_WHEEL] = Component.Identifier.Axis.Y; absAxesIDs[NativeDefinitions.ABS_GAS] = Component.Identifier.Axis.SLIDER; absAxesIDs[NativeDefinitions.ABS_BRAKE] = Component.Identifier.Axis.SLIDER; // Hats are done this way as they are mapped from two axis down to one absAxesIDs[NativeDefinitions.ABS_HAT0X] = Component.Identifier.Axis.POV; absAxesIDs[NativeDefinitions.ABS_HAT0Y] = Component.Identifier.Axis.POV; absAxesIDs[NativeDefinitions.ABS_HAT1X] = Component.Identifier.Axis.POV; absAxesIDs[NativeDefinitions.ABS_HAT1Y] = Component.Identifier.Axis.POV; absAxesIDs[NativeDefinitions.ABS_HAT2X] = Component.Identifier.Axis.POV; absAxesIDs[NativeDefinitions.ABS_HAT2Y] = Component.Identifier.Axis.POV; absAxesIDs[NativeDefinitions.ABS_HAT3X] = Component.Identifier.Axis.POV; absAxesIDs[NativeDefinitions.ABS_HAT3Y] = Component.Identifier.Axis.POV; // erm, yeah absAxesIDs[NativeDefinitions.ABS_PRESSURE] = null; absAxesIDs[NativeDefinitions.ABS_DISTANCE] = null; absAxesIDs[NativeDefinitions.ABS_TILT_X] = null; absAxesIDs[NativeDefinitions.ABS_TILT_Y] = null; absAxesIDs[NativeDefinitions.ABS_MISC] = null; } public final static Controller.Type guessButtonTrait(int button_code) { switch (button_code) { case NativeDefinitions.BTN_TRIGGER : case NativeDefinitions.BTN_THUMB : case NativeDefinitions.BTN_THUMB2 : case NativeDefinitions.BTN_TOP : case NativeDefinitions.BTN_TOP2 : case NativeDefinitions.BTN_PINKIE : case NativeDefinitions.BTN_BASE : case NativeDefinitions.BTN_BASE2 : case NativeDefinitions.BTN_BASE3 : case NativeDefinitions.BTN_BASE4 : case NativeDefinitions.BTN_BASE5 : case NativeDefinitions.BTN_BASE6 : case NativeDefinitions.BTN_DEAD : return Controller.Type.STICK; case NativeDefinitions.BTN_A : case NativeDefinitions.BTN_B : case NativeDefinitions.BTN_C : case NativeDefinitions.BTN_X : case NativeDefinitions.BTN_Y : case NativeDefinitions.BTN_Z : case NativeDefinitions.BTN_TL : case NativeDefinitions.BTN_TR : case NativeDefinitions.BTN_TL2 : case NativeDefinitions.BTN_TR2 : case NativeDefinitions.BTN_SELECT : case NativeDefinitions.BTN_MODE : case NativeDefinitions.BTN_THUMBL : case NativeDefinitions.BTN_THUMBR : return Controller.Type.GAMEPAD; case NativeDefinitions.BTN_0 : case NativeDefinitions.BTN_1 : case NativeDefinitions.BTN_2 : case NativeDefinitions.BTN_3 : case NativeDefinitions.BTN_4 : case NativeDefinitions.BTN_5 : case NativeDefinitions.BTN_6 : case NativeDefinitions.BTN_7 : case NativeDefinitions.BTN_8 : case NativeDefinitions.BTN_9 : return Controller.Type.UNKNOWN; case NativeDefinitions.BTN_LEFT : case NativeDefinitions.BTN_RIGHT : case NativeDefinitions.BTN_MIDDLE : case NativeDefinitions.BTN_SIDE : case NativeDefinitions.BTN_EXTRA : return Controller.Type.MOUSE; // case NativeDefinitions.KEY_RESERVED: case NativeDefinitions.KEY_ESC: case NativeDefinitions.KEY_1: case NativeDefinitions.KEY_2: case NativeDefinitions.KEY_3: case NativeDefinitions.KEY_4: case NativeDefinitions.KEY_5: case NativeDefinitions.KEY_6: case NativeDefinitions.KEY_7: case NativeDefinitions.KEY_8: case NativeDefinitions.KEY_9: case NativeDefinitions.KEY_0: case NativeDefinitions.KEY_MINUS: case NativeDefinitions.KEY_EQUAL: case NativeDefinitions.KEY_BACKSPACE: case NativeDefinitions.KEY_TAB: case NativeDefinitions.KEY_Q: case NativeDefinitions.KEY_W: case NativeDefinitions.KEY_E: case NativeDefinitions.KEY_R: case NativeDefinitions.KEY_T: case NativeDefinitions.KEY_Y: case NativeDefinitions.KEY_U: case NativeDefinitions.KEY_I: case NativeDefinitions.KEY_O: case NativeDefinitions.KEY_P: case NativeDefinitions.KEY_LEFTBRACE: case NativeDefinitions.KEY_RIGHTBRACE: case NativeDefinitions.KEY_ENTER: case NativeDefinitions.KEY_LEFTCTRL: case NativeDefinitions.KEY_A: case NativeDefinitions.KEY_S: case NativeDefinitions.KEY_D: case NativeDefinitions.KEY_F: case NativeDefinitions.KEY_G: case NativeDefinitions.KEY_H: case NativeDefinitions.KEY_J: case NativeDefinitions.KEY_K: case NativeDefinitions.KEY_L: case NativeDefinitions.KEY_SEMICOLON: case NativeDefinitions.KEY_APOSTROPHE: case NativeDefinitions.KEY_GRAVE: case NativeDefinitions.KEY_LEFTSHIFT: case NativeDefinitions.KEY_BACKSLASH: case NativeDefinitions.KEY_Z: case NativeDefinitions.KEY_X: case NativeDefinitions.KEY_C: case NativeDefinitions.KEY_V: case NativeDefinitions.KEY_B: case NativeDefinitions.KEY_N: case NativeDefinitions.KEY_M: case NativeDefinitions.KEY_COMMA: case NativeDefinitions.KEY_DOT: case NativeDefinitions.KEY_SLASH: case NativeDefinitions.KEY_RIGHTSHIFT: case NativeDefinitions.KEY_KPASTERISK: case NativeDefinitions.KEY_LEFTALT: case NativeDefinitions.KEY_SPACE: case NativeDefinitions.KEY_CAPSLOCK: case NativeDefinitions.KEY_F1: case NativeDefinitions.KEY_F2: case NativeDefinitions.KEY_F3: case NativeDefinitions.KEY_F4: case NativeDefinitions.KEY_F5: case NativeDefinitions.KEY_F6: case NativeDefinitions.KEY_F7: case NativeDefinitions.KEY_F8: case NativeDefinitions.KEY_F9: case NativeDefinitions.KEY_F10: case NativeDefinitions.KEY_NUMLOCK: case NativeDefinitions.KEY_SCROLLLOCK: case NativeDefinitions.KEY_KP7: case NativeDefinitions.KEY_KP8: case NativeDefinitions.KEY_KP9: case NativeDefinitions.KEY_KPMINUS: case NativeDefinitions.KEY_KP4: case NativeDefinitions.KEY_KP5: case NativeDefinitions.KEY_KP6: case NativeDefinitions.KEY_KPPLUS: case NativeDefinitions.KEY_KP1: case NativeDefinitions.KEY_KP2: case NativeDefinitions.KEY_KP3: case NativeDefinitions.KEY_KP0: case NativeDefinitions.KEY_KPDOT: case NativeDefinitions.KEY_ZENKAKUHANKAKU: case NativeDefinitions.KEY_102ND: case NativeDefinitions.KEY_F11: case NativeDefinitions.KEY_F12: case NativeDefinitions.KEY_RO: case NativeDefinitions.KEY_KATAKANA: case NativeDefinitions.KEY_HIRAGANA: case NativeDefinitions.KEY_HENKAN: case NativeDefinitions.KEY_KATAKANAHIRAGANA: case NativeDefinitions.KEY_MUHENKAN: case NativeDefinitions.KEY_KPJPCOMMA: case NativeDefinitions.KEY_KPENTER: case NativeDefinitions.KEY_RIGHTCTRL: case NativeDefinitions.KEY_KPSLASH: case NativeDefinitions.KEY_SYSRQ: case NativeDefinitions.KEY_RIGHTALT: case NativeDefinitions.KEY_LINEFEED: case NativeDefinitions.KEY_HOME: case NativeDefinitions.KEY_UP: case NativeDefinitions.KEY_PAGEUP: case NativeDefinitions.KEY_LEFT: case NativeDefinitions.KEY_RIGHT: case NativeDefinitions.KEY_END: case NativeDefinitions.KEY_DOWN: case NativeDefinitions.KEY_PAGEDOWN: case NativeDefinitions.KEY_INSERT: case NativeDefinitions.KEY_DELETE: case NativeDefinitions.KEY_MACRO: case NativeDefinitions.KEY_MUTE: case NativeDefinitions.KEY_VOLUMEDOWN: case NativeDefinitions.KEY_VOLUMEUP: case NativeDefinitions.KEY_POWER: case NativeDefinitions.KEY_KPEQUAL: case NativeDefinitions.KEY_KPPLUSMINUS: case NativeDefinitions.KEY_PAUSE: case NativeDefinitions.KEY_KPCOMMA: case NativeDefinitions.KEY_HANGUEL: case NativeDefinitions.KEY_HANJA: case NativeDefinitions.KEY_YEN: case NativeDefinitions.KEY_LEFTMETA: case NativeDefinitions.KEY_RIGHTMETA: case NativeDefinitions.KEY_COMPOSE: case NativeDefinitions.KEY_STOP: case NativeDefinitions.KEY_AGAIN: case NativeDefinitions.KEY_PROPS: case NativeDefinitions.KEY_UNDO: case NativeDefinitions.KEY_FRONT: case NativeDefinitions.KEY_COPY: case NativeDefinitions.KEY_OPEN: case NativeDefinitions.KEY_PASTE: case NativeDefinitions.KEY_FIND: case NativeDefinitions.KEY_CUT: case NativeDefinitions.KEY_HELP: case NativeDefinitions.KEY_MENU: case NativeDefinitions.KEY_CALC: case NativeDefinitions.KEY_SETUP: case NativeDefinitions.KEY_SLEEP: case NativeDefinitions.KEY_WAKEUP: case NativeDefinitions.KEY_FILE: case NativeDefinitions.KEY_SENDFILE: case NativeDefinitions.KEY_DELETEFILE: case NativeDefinitions.KEY_XFER: case NativeDefinitions.KEY_PROG1: case NativeDefinitions.KEY_PROG2: case NativeDefinitions.KEY_WWW: case NativeDefinitions.KEY_MSDOS: case NativeDefinitions.KEY_COFFEE: case NativeDefinitions.KEY_DIRECTION: case NativeDefinitions.KEY_CYCLEWINDOWS: case NativeDefinitions.KEY_MAIL: case NativeDefinitions.KEY_BOOKMARKS: case NativeDefinitions.KEY_COMPUTER: case NativeDefinitions.KEY_BACK: case NativeDefinitions.KEY_FORWARD: case NativeDefinitions.KEY_CLOSECD: case NativeDefinitions.KEY_EJECTCD: case NativeDefinitions.KEY_EJECTCLOSECD: case NativeDefinitions.KEY_NEXTSONG: case NativeDefinitions.KEY_PLAYPAUSE: case NativeDefinitions.KEY_PREVIOUSSONG: case NativeDefinitions.KEY_STOPCD: case NativeDefinitions.KEY_RECORD: case NativeDefinitions.KEY_REWIND: case NativeDefinitions.KEY_PHONE: case NativeDefinitions.KEY_ISO: case NativeDefinitions.KEY_CONFIG: case NativeDefinitions.KEY_HOMEPAGE: case NativeDefinitions.KEY_REFRESH: case NativeDefinitions.KEY_EXIT: case NativeDefinitions.KEY_MOVE: case NativeDefinitions.KEY_EDIT: case NativeDefinitions.KEY_SCROLLUP: case NativeDefinitions.KEY_SCROLLDOWN: case NativeDefinitions.KEY_KPLEFTPAREN: case NativeDefinitions.KEY_KPRIGHTPAREN: case NativeDefinitions.KEY_F13: case NativeDefinitions.KEY_F14: case NativeDefinitions.KEY_F15: case NativeDefinitions.KEY_F16: case NativeDefinitions.KEY_F17: case NativeDefinitions.KEY_F18: case NativeDefinitions.KEY_F19: case NativeDefinitions.KEY_F20: case NativeDefinitions.KEY_F21: case NativeDefinitions.KEY_F22: case NativeDefinitions.KEY_F23: case NativeDefinitions.KEY_F24: case NativeDefinitions.KEY_PLAYCD: case NativeDefinitions.KEY_PAUSECD: case NativeDefinitions.KEY_PROG3: case NativeDefinitions.KEY_PROG4: case NativeDefinitions.KEY_SUSPEND: case NativeDefinitions.KEY_CLOSE: case NativeDefinitions.KEY_PLAY: case NativeDefinitions.KEY_FASTFORWARD: case NativeDefinitions.KEY_BASSBOOST: case NativeDefinitions.KEY_PRINT: case NativeDefinitions.KEY_HP: case NativeDefinitions.KEY_CAMERA: case NativeDefinitions.KEY_SOUND: case NativeDefinitions.KEY_QUESTION: case NativeDefinitions.KEY_EMAIL: case NativeDefinitions.KEY_CHAT: case NativeDefinitions.KEY_SEARCH: case NativeDefinitions.KEY_CONNECT: case NativeDefinitions.KEY_FINANCE: case NativeDefinitions.KEY_SPORT: case NativeDefinitions.KEY_SHOP: case NativeDefinitions.KEY_ALTERASE: case NativeDefinitions.KEY_CANCEL: case NativeDefinitions.KEY_BRIGHTNESSDOWN: case NativeDefinitions.KEY_BRIGHTNESSUP: case NativeDefinitions.KEY_MEDIA: case NativeDefinitions.KEY_SWITCHVIDEOMODE: case NativeDefinitions.KEY_KBDILLUMTOGGLE: case NativeDefinitions.KEY_KBDILLUMDOWN: case NativeDefinitions.KEY_KBDILLUMUP: // case NativeDefinitions.KEY_UNKNOWN: case NativeDefinitions.KEY_OK: case NativeDefinitions.KEY_SELECT: case NativeDefinitions.KEY_GOTO: case NativeDefinitions.KEY_CLEAR: case NativeDefinitions.KEY_POWER2: case NativeDefinitions.KEY_OPTION: case NativeDefinitions.KEY_INFO: case NativeDefinitions.KEY_TIME: case NativeDefinitions.KEY_VENDOR: case NativeDefinitions.KEY_ARCHIVE: case NativeDefinitions.KEY_PROGRAM: case NativeDefinitions.KEY_CHANNEL: case NativeDefinitions.KEY_FAVORITES: case NativeDefinitions.KEY_EPG: case NativeDefinitions.KEY_PVR: case NativeDefinitions.KEY_MHP: case NativeDefinitions.KEY_LANGUAGE: case NativeDefinitions.KEY_TITLE: case NativeDefinitions.KEY_SUBTITLE: case NativeDefinitions.KEY_ANGLE: case NativeDefinitions.KEY_ZOOM: case NativeDefinitions.KEY_MODE: case NativeDefinitions.KEY_KEYBOARD: case NativeDefinitions.KEY_SCREEN: case NativeDefinitions.KEY_PC: case NativeDefinitions.KEY_TV: case NativeDefinitions.KEY_TV2: case NativeDefinitions.KEY_VCR: case NativeDefinitions.KEY_VCR2: case NativeDefinitions.KEY_SAT: case NativeDefinitions.KEY_SAT2: case NativeDefinitions.KEY_CD: case NativeDefinitions.KEY_TAPE: case NativeDefinitions.KEY_RADIO: case NativeDefinitions.KEY_TUNER: case NativeDefinitions.KEY_PLAYER: case NativeDefinitions.KEY_TEXT: case NativeDefinitions.KEY_DVD: case NativeDefinitions.KEY_AUX: case NativeDefinitions.KEY_MP3: case NativeDefinitions.KEY_AUDIO: case NativeDefinitions.KEY_VIDEO: case NativeDefinitions.KEY_DIRECTORY: case NativeDefinitions.KEY_LIST: case NativeDefinitions.KEY_MEMO: case NativeDefinitions.KEY_CALENDAR: case NativeDefinitions.KEY_RED: case NativeDefinitions.KEY_GREEN: case NativeDefinitions.KEY_YELLOW: case NativeDefinitions.KEY_BLUE: case NativeDefinitions.KEY_CHANNELUP: case NativeDefinitions.KEY_CHANNELDOWN: case NativeDefinitions.KEY_FIRST: case NativeDefinitions.KEY_LAST: case NativeDefinitions.KEY_AB: case NativeDefinitions.KEY_NEXT: case NativeDefinitions.KEY_RESTART: case NativeDefinitions.KEY_SLOW: case NativeDefinitions.KEY_SHUFFLE: case NativeDefinitions.KEY_BREAK: case NativeDefinitions.KEY_PREVIOUS: case NativeDefinitions.KEY_DIGITS: case NativeDefinitions.KEY_TEEN: case NativeDefinitions.KEY_TWEN: case NativeDefinitions.KEY_DEL_EOL: case NativeDefinitions.KEY_DEL_EOS: case NativeDefinitions.KEY_INS_LINE: case NativeDefinitions.KEY_DEL_LINE: case NativeDefinitions.KEY_FN: case NativeDefinitions.KEY_FN_ESC: case NativeDefinitions.KEY_FN_F1: case NativeDefinitions.KEY_FN_F2: case NativeDefinitions.KEY_FN_F3: case NativeDefinitions.KEY_FN_F4: case NativeDefinitions.KEY_FN_F5: case NativeDefinitions.KEY_FN_F6: case NativeDefinitions.KEY_FN_F7: case NativeDefinitions.KEY_FN_F8: case NativeDefinitions.KEY_FN_F9: case NativeDefinitions.KEY_FN_F10: case NativeDefinitions.KEY_FN_F11: case NativeDefinitions.KEY_FN_F12: case NativeDefinitions.KEY_FN_1: case NativeDefinitions.KEY_FN_2: case NativeDefinitions.KEY_FN_D: case NativeDefinitions.KEY_FN_E: case NativeDefinitions.KEY_FN_F: case NativeDefinitions.KEY_FN_S: case NativeDefinitions.KEY_FN_B: return Controller.Type.KEYBOARD; default: return Controller.Type.UNKNOWN; } } /** Return port type from a native port type int id * @param nativeid The native port type * @return The jinput port type */ public static Controller.PortType getPortType(int nativeid) { // Have to do this one this way as there is no BUS_MAX switch (nativeid) { case NativeDefinitions.BUS_GAMEPORT : return Controller.PortType.GAME; case NativeDefinitions.BUS_I8042 : return Controller.PortType.I8042; case NativeDefinitions.BUS_PARPORT : return Controller.PortType.PARALLEL; case NativeDefinitions.BUS_RS232 : return Controller.PortType.SERIAL; case NativeDefinitions.BUS_USB : return Controller.PortType.USB; default: return Controller.PortType.UNKNOWN; } } /** Gets the identifier for a relative axis * @param nativeID The axis type ID * @return The jinput id */ public static Component.Identifier getRelAxisID(int nativeID) { Component.Identifier retval = null; try { retval = INSTANCE.relAxesIDs[nativeID]; } catch (ArrayIndexOutOfBoundsException e) { log.warning("INSTANCE.relAxesIDis only " + INSTANCE.relAxesIDs.length + " long, so " + nativeID + " not contained"); //ignore, pretend it was null } if(retval == null) { retval = Component.Identifier.Axis.SLIDER_VELOCITY; } return retval; } /** Gets the identifier for a absolute axis * @param nativeID The native axis type id * @return The jinput id */ public static Component.Identifier getAbsAxisID(int nativeID) { Component.Identifier retval = null; try { retval = INSTANCE.absAxesIDs[nativeID]; } catch (ArrayIndexOutOfBoundsException e) { log.warning("INSTANCE.absAxesIDs is only " + INSTANCE.absAxesIDs.length + " long, so " + nativeID + " not contained"); //ignore, pretend it was null } if(retval == null) { retval = Component.Identifier.Axis.SLIDER; } return retval; } /** Gets the identifier for a button * @param nativeID The native button type id * @return The jinput id */ public static Component.Identifier getButtonID(int nativeID) { Component.Identifier retval = null; try { retval = INSTANCE.buttonIDs[nativeID]; } catch (ArrayIndexOutOfBoundsException e) { log.warning("INSTANCE.buttonIDs is only " + INSTANCE.buttonIDs.length + " long, so " + nativeID + " not contained"); //ignore, pretend it was null } if(retval == null) { retval = Component.Identifier.Key.UNKNOWN; } return retval; } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxConstantFF.java0000644000175000017500000000362010424764262027406 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.io.IOException; /** * @author elias */ final class LinuxConstantFF extends LinuxForceFeedbackEffect { public LinuxConstantFF(LinuxEventDevice device) throws IOException { super(device); } protected final int upload(int id, float intensity) throws IOException { int scaled_intensity = Math.round(intensity*0x7fff); return getDevice().uploadConstantEffect(id, 0, 0, 0, 0, 0, scaled_intensity, 0, 0, 0, 0); } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxForceFeedbackEffect.java0000644000175000017500000000665310633011276031162 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.io.IOException; /** * @author elias */ abstract class LinuxForceFeedbackEffect implements Rumbler { private final LinuxEventDevice device; private final int ff_id; private final WriteTask write_task = new WriteTask(); private final UploadTask upload_task = new UploadTask(); public LinuxForceFeedbackEffect(LinuxEventDevice device) throws IOException { this.device = device; this.ff_id = upload_task.doUpload(-1, 0); } protected abstract int upload(int id, float intensity) throws IOException; protected final LinuxEventDevice getDevice() { return device; } public synchronized final void rumble(float intensity) { try { if (intensity > 0) { upload_task.doUpload(ff_id, intensity); write_task.write(1); } else { write_task.write(0); } } catch (IOException e) { LinuxEnvironmentPlugin.logln("Failed to rumble: " + e); } } /* * Erase doesn't seem to be implemented on Logitech joysticks, * so we'll rely on the kernel cleaning up on device close */ /* public final void erase() throws IOException { device.eraseEffect(ff_id); } */ public final String getAxisName() { return null; } public final Component.Identifier getAxisIdentifier() { return null; } private final class UploadTask extends LinuxDeviceTask { private int id; private float intensity; public final int doUpload(int id, float intensity) throws IOException { this.id = id; this.intensity = intensity; LinuxEnvironmentPlugin.execute(this); return this.id; } protected final Object execute() throws IOException { this.id = upload(id, intensity); return null; } } private final class WriteTask extends LinuxDeviceTask { private int value; public final void write(int value) throws IOException { this.value = value; LinuxEnvironmentPlugin.execute(this); } protected final Object execute() throws IOException { device.writeEvent(NativeDefinitions.EV_FF, ff_id, value); return null; } } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxMouse.java0000644000175000017500000000540510424764261026473 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents an OSX Mouse * @author elias * @version 1.0 */ final class LinuxMouse extends Mouse { private final PortType port; private final LinuxEventDevice device; protected LinuxMouse(LinuxEventDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) throws IOException { super(device.getName(), components, children, rumblers); this.device = device; this.port = device.getPortType(); } public final PortType getPortType() { return port; } public final void pollDevice() throws IOException { device.pollKeyStates(); } protected final boolean getNextDeviceEvent(Event event) throws IOException { return LinuxControllers.getNextDeviceEvent(event, device); } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java0000644000175000017500000000542110424764261027141 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents an OSX Keyboard * @author elias * @version 1.0 */ final class LinuxKeyboard extends Keyboard { private final PortType port; private final LinuxEventDevice device; protected LinuxKeyboard(LinuxEventDevice device, Component[] components, Controller[] children, Rumbler[] rumblers) throws IOException { super(device.getName(), components, children, rumblers); this.device = device; this.port = device.getPortType(); } public final PortType getPortType() { return port; } protected final boolean getNextDeviceEvent(Event event) throws IOException { return LinuxControllers.getNextDeviceEvent(event, device); } public final void pollDevice() throws IOException { device.pollKeyStates(); } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxAxisDescriptor.java0000644000175000017500000000425610424764262030352 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; /** * @author elias */ final class LinuxAxisDescriptor { private int type; private int code; public final void set(int type, int code) { this.type = type; this.code = code; } public final int getType() { return type; } public final int getCode() { return code; } public final int hashCode() { return type ^ code; } public final boolean equals(Object other) { if (!(other instanceof LinuxAxisDescriptor)) return false; LinuxAxisDescriptor descriptor = (LinuxAxisDescriptor)other; return descriptor.type == type && descriptor.code == code; } public final String toString() { return "LinuxAxis: type = 0x" + Integer.toHexString(type) + ", code = 0x" + Integer.toHexString(code); } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxRumbleFF.java0000644000175000017500000000434010424764265027046 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; import java.io.IOException; /** * @author elias */ final class LinuxRumbleFF extends LinuxForceFeedbackEffect { public LinuxRumbleFF(LinuxEventDevice device) throws IOException { super(device); } protected final int upload(int id, float intensity) throws IOException { int weak_magnitude; int strong_magnitude; if (intensity > 0.666666f) { strong_magnitude = (int)(0x8000*intensity); weak_magnitude = (int)(0xc000*intensity); } else if (intensity > 0.3333333f) { strong_magnitude = (int)(0x8000*intensity); weak_magnitude = (int)(0xc000*0); } else { strong_magnitude = (int)(0x8000*0); weak_magnitude = (int)(0xc000*intensity); } return getDevice().uploadRumbleEffect(id, 0, 0, 0, -1, 0, strong_magnitude, weak_magnitude); } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxJoystickPOV.java0000644000175000017500000000257710657701275027602 0ustar twernertwernerpackage net.java.games.input; import java.io.IOException; public class LinuxJoystickPOV extends LinuxJoystickAxis { private LinuxJoystickAxis hatX; private LinuxJoystickAxis hatY; LinuxJoystickPOV(Component.Identifier.Axis id, LinuxJoystickAxis hatX, LinuxJoystickAxis hatY) { super(id, false); this.hatX = hatX; this.hatY = hatY; } protected LinuxJoystickAxis getXAxis() { return hatX; } protected LinuxJoystickAxis getYAxis() { return hatY; } protected void updateValue() { float last_x = hatX.getPollData(); float last_y = hatY.getPollData(); resetHasPolled(); if (last_x == -1 && last_y == -1) setValue(Component.POV.UP_LEFT); else if (last_x == -1 && last_y == 0) setValue(Component.POV.LEFT); else if (last_x == -1 && last_y == 1) setValue(Component.POV.DOWN_LEFT); else if (last_x == 0 && last_y == -1) setValue(Component.POV.UP); else if (last_x == 0 && last_y == 0) setValue(Component.POV.OFF); else if (last_x == 0 && last_y == 1) setValue(Component.POV.DOWN); else if (last_x == 1 && last_y == -1) setValue(Component.POV.UP_RIGHT); else if (last_x == 1 && last_y == 0) setValue(Component.POV.RIGHT); else if (last_x == 1 && last_y == 1) setValue(Component.POV.DOWN_RIGHT); else { LinuxEnvironmentPlugin.logln("Unknown values x = " + last_x + " | y = " + last_y); setValue(Component.POV.OFF); } } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxJoystickEvent.java0000644000175000017500000000374110424764265030211 0ustar twernertwerner/** * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided * with the distribution. * The name of the author may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; /** * @author elias */ final class LinuxJoystickEvent { private long nanos; private int value; private int type; private int number; public final void set(long millis, int value, int type, int number) { this.nanos = millis*1000000; this.value = value; this.type = type; this.number = number; } public final int getValue() { return value; } public final int getType() { return type; } public final int getNumber() { return number; } public final long getNanos() { return nanos; } } jinput-20100502/plugins/linux/src/java/net/java/games/input/LinuxJoystickButton.java0000644000175000017500000000502210657701275030375 0ustar twernertwerner/* * %W% %E% * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materails provided with the distribution. * * Neither the name Sun Microsystems, Inc. or the names of the contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * *****************************************************************************/ package net.java.games.input; import java.io.IOException; /** Represents a linux button from the joystick interface * @author elias * @version 1.0 */ final class LinuxJoystickButton extends AbstractComponent { private float value; public LinuxJoystickButton(Component.Identifier button_id) { super(button_id.getName(), button_id); } public final boolean isRelative() { return false; } final void setValue(float value) { this.value = value; } protected final float poll() throws IOException { return value; } } jinput-20100502/plugins/linux/build.xml0000644000175000017500000000506310455011432017654 0ustar twernertwerner