Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JInput not working correctly in applets  (Read 5349 times)
0 Members and 1 Guest are viewing this topic.
Offline ryanheise

Junior Newbie





« Posted 2009-03-21 16:05:28 »

I am developing an applet that will use JInput if it is present (in the user's "lib/ext" directory), or will otherwise fall back to standard java.awt techniques.

Here is the problem:

When JInput is detected on LINUX, keyboard events are detected fine, but mouse events are not.
When JInput is detected on WINDOWS, mouse events are detected fine, but keyboard events are not.

My game depends on keyboard input, so the second problem is worse for me.

Here is the code I'm using to see what events are being detected by JInput:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
Event event = new Event();
while (...)
{
    for (int i = 0; i < controllers.length; i++)
    {
        controllers[i].poll();
        EventQueue queue = controllers[i].getEventQueue();
        while(queue.getNextEvent(event))
            System.out.println(event);
    }
}

By printing out the array of controllers, I can also verify that a keyboard controller is found by JInput in both WINDOWS and LINUX, but it just doesn't do anything in WINDOWS.

I noticed that a similar problem was described in the thread "JInput and Java 1.6.0_10" although this might be a different problem because in my case there is evidence that things are at least "partially" working.

Is there a solution that doesn't fundamentally change the delivery approach of an applet loading JInput from lib/ext?

My LINUX Java version is 1.6.0_10-beta-b14 (but I unfortunately don't have the WINDOWS Java version at hand).

Thank you
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #1 - Posted 2009-03-21 17:53:25 »

Hi

If the mouse or keyboard is successfully detected, then the loading from lib/ext isn't the issue. I don't know why it might happen, but have you tried just getting one event in the loop instead of emptying the queue, it sounds like one device is keeping the code in the inner part of the loop.

HTH

Endolf

Offline ryanheise

Junior Newbie





« Reply #2 - Posted 2009-03-21 23:59:21 »

If I print "Checking for events" just before the inner loop, the program shows that the outer loop is repeating regularly, so this is not it.

Also, if I use keyboard.isKeyDown(...) instead of events, this method always returns false on WINDOWS.

Were you able to reproduce the problem with the code I provided?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #3 - Posted 2009-03-22 10:17:12 »

Running your code I get no events at all.

I'm out for the day, but I hope to have a look at this this evening.

Endolf

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #4 - Posted 2009-03-22 10:20:17 »

If I stick a jframe in there it works.

JInput *should* work from the console, not sure whats changed. I'll look later.

Endolf

Offline ryanheise

Junior Newbie





« Reply #5 - Posted 2009-03-22 10:28:45 »

I'm also not running this code from a console, for me, I used it in an applet.

By the way, another option is to try the game to see if you get the same problem with my code: http://hi-games.net/tessellate-t,lt,O,d/

The polled keys are: Z, X, Arrow keys and Space. You can press F9 *after* the game has started to see if JInput was detected by the applet (if it says "Direct", then it was detected).

When JInput is in lib/ext, keyboard input works on Linux, but not on Windows. When JInput is not in lib/ext, it works on all platforms using standard AWT events.

Thanks for looking into the problem.
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #6 - Posted 2009-03-22 15:08:08 »

I looked at the game, the keys read fine, but I got no direct anywhere I could see.
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #7 - Posted 2009-03-22 23:16:17 »

I created a resource loader for JInput in applets a little while ago that downloads the native files to the users machine. You can try it here. That seems to work using events. I created a test using your code and it works perfectly using that method.

With no window at all, I get no events reported, this is because JInput on windows by default uses raw input for keyboard/mice and directx for everything else, but this method requires the application to have focus. If you provide the properties
1  
-Djinput.useDefaultPlugin=false -Djinput.plugins=net.java.games.input.DirectInputEnvironmentPlugin

it will use directx only and will read the keyboard/mouse. The down side is that multiple mice/keyboards are not supported.

HTH

Endolf

Offline ryanheise

Junior Newbie





« Reply #8 - Posted 2009-03-23 00:54:40 »

Hi endolf, I saw your resource loader before actually. It's really cool, nice job! And, it works. But... as I mentioned, I would like not to change my delivery mechanism.

Could it be that the reason your applet works has nothing to do with the resource loader (and would work just as well with lib/ext), and has more to do with the fact that your applet creates JFrames? Can you make a normal applet that runs entirely inside of the applet component and can poll the keyboard using JInput? This would correspond more to what I am hoping to achieve.

If I set the plugin to directx as you suggested, it is then possible to poll the keyboard from within the applet. This is great, except that in order to set the various properties, the applet must be signed, and this changes my delivery mechanism. I do not want users to have to click a button to trust this applet. Also, you mentioned that the directx plugin does not support multiple keyboards and mice. This is ok, but how about joysticks? I will eventually want to support a joystick inside the applet.

Ideally, JInput could be fixed to work inside an applet by default. Is this possible? Thanks again.
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #9 - Posted 2009-03-23 07:43:00 »

I ran your own code within an applet, so no JFrame, and that worked fine using the jinput resource loader.
Using directx only will support multiple joysticks.
JInput will not work without signing the applet, there are too many calls that are restricted. Most of them are to do with checking the configuration, but loading the dll/so/jnilib will also not work inside an unsigned applet.

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanheise

Junior Newbie





« Reply #10 - Posted 2009-03-23 10:38:01 »

If the JInput jar is placed into lib/ext, isn't it automatically granted the privileges to access whatever it needs to access?
Offline cylab

JGO Ninja


Medals: 55



« Reply #11 - Posted 2009-03-23 15:28:07 »

If the JInput jar is placed into lib/ext, isn't it automatically granted the privileges to access whatever it needs to access?

Don't EVER put sumething into lib/ext, if don't know exactly what you are doing. There are multiple problems with this approach:

1. You may break webstart code and applets using a
    different version of jinput than you

2. The dlls/natives won't get loaded from lib/ext, so you have
    to put them to some system library path

3. You will have to tell your users to put the files to
    various (delecate) directories on their system
    (you can't acces the harddisk from a non-signed applet)

4. The applet still won't have access to native code (dlls)
    when unsigned. You could completely circumvent applet
    security otherwise (using win32 native file access for
    example to spread viruses)

5. You would encourage ALL YOUR USERS to get problem no. 1!!!

Mathias - I Know What [you] Did Last Summer!
Offline ryanheise

Junior Newbie





« Reply #12 - Posted 2009-03-23 15:58:42 »

Is the JInput API really unstable? I would hope that if major, incompatible changes were ever made to the JInput API, then it would be given a new package name so as not to clash with the previous version. If there is no goal to do this, then I suppose (1) is a valid point.

However are you sure about (2) and (4)? I have verified that the native libraries do get loaded from lib/ext, even from an unsigned applet.
Offline cylab

JGO Ninja


Medals: 55



« Reply #13 - Posted 2009-03-23 16:24:31 »

However are you sure about (2) and (4)? I have verified that the native libraries do get loaded from lib/ext, even from an unsigned applet.

I am not. I just made an "educated guess", so if you verified this works, I don't seem to be as educated as I thought Wink

Mathias - I Know What [you] Did Last Summer!
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #14 - Posted 2009-03-24 07:30:37 »

If there were major changes that were not compatable with the current version of JInput, it would get a new version number, not a name. More importantly, security changes or other bugs would have to be manually updates as per point 1.
I would have thought that if signed applet dialogs were a worry, point 3 would be an issue.

On the other hand, I would like to get this working for you. I have 3 days off this week, not all of it is free time, but I hope to get a chance to look at doing things from lib/ext

HTH

Endolf

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!