JInput does not generate events for semicolon and apostrophe

Under Win7, JInput does not appear to generate events for the semicolon and apostrophe keys among several others. Is there a work-around?

Update to the latest version or a previous version.

Unless it is open source, which you would then check if they disabled those keys, it should be registered as a problem.

My project uses the JInput resources exclusively. It doesn’t seem to have access to the LWJGL classes in your test code.

I upgraded to the latest nightly JInput build and the problem still persists. Can someone else check on their Win7 box if JInput is capable to receiving events for semicolor or apostrophe? Thanks.

Edit: I can get it to work if I add these VM arguments:

-Djinput.useDefaultPlugin=false -Djinput.plugins=net.java.games.input.DirectInputEnvironmentPlugin

Is there any issue to using them? Is there a way to set that directly from the running app?

From the source:

            //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") || osName.equals("Windows 8") || osName.equals("Windows 8.1") || osName.equals("Windows 10")) {
					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.warning("Attempting to use default windows plug-in.");
					pluginClasses = pluginClasses + " net.java.games.input.DirectAndRawInputEnvironmentPlugin";
				} else {
					log.warning("Trying to use default plugin, OS name " + osName +" not recognised");
				}
			}

Windows XP and above gets:

net.java.games.input.DirectAndRawInputEnvironmentPlugin

Older versions of windows gets:

net.java.games.input.DirectInputEnvironmentPlugin

I don’t know what the difference is between these plugins, but the newer one is not able to pick up some keyboard buttons at least under Windows 7.

Can anyone shed some light on this?

Not sure why it’s not picking up those keys (potential bug), anyway this thread sheds some light on it:

http://www.java-gaming.org/index.php?topic=21528.0

The raw plugin is so that you can use multiple (of the same) input devices, this might also affect console controllers (meaning that connecting a controller might cause unintended side-effects).

That link suggests that only the keyboards and mice are combined, which is sensible; rarely if ever do you attach multiple keyboards or mice to the same machine.

If it is a bug, it could be specific to my keyboard since it relies on the low level keyboard events (it’s a typical Logitech keyboard from about 2 years ago, nothing special or unusual about it). It’s more likely something to do with box:

Windows 7 Professional
Service Pack 1
Dell
5.1 Windows Experience Index
Intel Core i5-2400 CPU @ 3.10GHz
8 GB RAM
64-bit OS

I would appreciate if others could test out those key events if they are running on a similar platform.

In the meantime, I think I’ll force it to use the non-raw plugin.

If you aren’t worried about people using multiple mice/keyboards/controllers then you’re fine to just use the old plugin (which was my point).

I’m not sure why you think it’s your machine that has the issue, update your keyboard driver. I also don’t see anything for anybody to run to test this.

Here’s a simple JInput test program. Most keys works for me. Semicolon and apostrophe do not generate any events.

import java.awt.*;
import javax.swing.*;
import net.java.games.input.*;

public class Main {

  private final net.java.games.input.Event event 
      = new net.java.games.input.Event();
  
  private Controller keyboard;  
  private JLabel label;
  
  public void launch() {
    createFrame();    
    initKeyboard();
    initTimer();   
  }
  
  private void createFrame() {
    final JFrame frame = new JFrame("Test Frame");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
    frame.setPreferredSize(new Dimension(640, 480));
    label = new JLabel("Press some keys.", SwingConstants.CENTER);
    label.setAlignmentY(0.5f);
    frame.setContentPane(label);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
  
  private void initKeyboard() {
    for(final Controller controller : ControllerEnvironment
        .getDefaultEnvironment().getControllers()) {
      if (controller.getType() == Controller.Type.KEYBOARD) {
        keyboard = controller;
        break;
      }
    }
  }
  
  private void initTimer() {
    final Timer timer = new Timer(25, e -> pollControllers());
    timer.start();
  }
  
  private void pollControllers() {
    if (keyboard != null) {
      if (keyboard.poll()) {
        final net.java.games.input.EventQueue queue = keyboard.getEventQueue();
        while(queue.getNextEvent(event)) {          
          label.setText(String.format("%s %d%n", 
              event.getComponent().getIdentifier().getName(),
                  (int)event.getValue()));
        }
      } else {
        keyboard = null;
      }
    }
  }
  
  public static void main(final String... args) throws Throwable {
    java.awt.EventQueue.invokeLater(new Main()::launch);
  }  
}

Just tested your code. Not getting / ; ’ \ = - I am getting / from the num pad though. win 7 64, latest jinput build.

Thanks for testing. The same keys fail here. Maybe it is some limitation of Windows Raw Input API.

Here’s my work-around for now:

    final String osName = System.getProperty("os.name");
    if (osName != null && osName.trim().toLowerCase().startsWith("win")) {
      System.setProperty("jinput.useDefaultPlugin", "false");
      System.setProperty("net.java.games.input.useDefaultPlugin", "false");
      System.setProperty("jinput.plugins", "");
      System.setProperty("net.java.games.input.plugins", 
          "net.java.games.input.DirectInputEnvironmentPlugin");
    }

I’ll verify, but I think this has no effect on the number of supported game controllers. It only consolidates keyboards and mice, similar to Swing’s keyboard and mouse events.

Interesting, I’m having the same problem in windows 7 64bit (I don’t have a 32bit machine to test on)

Controllers seem fine though and I don’t have this issue on windows 8.1 64bit.