Skip to main content
gamedev.net
🔒 Locked

[java] Java Event Polling

Started by Preacher Jan 14, 2005 at 5:38 AM 5 replies 1.6k views
Original Post
Preacher
Preacher
Hi im developing an game and i need to poll for key and mouse events actively rather than the traditional passive event listeners, as i think the listeners are flodding my program with to many events causing periodic slow down, and i'd like more control over the sampling rate of events anyway. Is their anyway of augmenting the event thread to do this? Ive just looked at JInput which can do the job but seems like an awkward port with little documentation (e.g. having to put the jinput.jar into a folder called "controller" in the root folder of every program). So i was wondering iof theres a way to do this with 100% Java???? Thanks :)
misterX
misterX
using the jdk there is no way to poll keyboard and mouse material directly, you can only listen to events in the usual way. Concerning apis to poll input directly, JInput is the only one i know.
If you have slow downs when recieving too many events, it's maybe because your event handling method is too heavy, alternatives would be to try making it lighter or to ignore some input in the case it's not vital to handle every tiny mouse move.
sorry, i can't help.
Preacher
Preacher
OK thanks for the time, i'll most likely use JInput although i would like to keep my program portable, i just thought there might be some polling architecture available, maybe something to suggest to java gaming community??
Painless
Painless
Are you redrawing on mouse/keyboard input? I've never had any problems taking keyboard/mouse input by listeners, but if your mouse/key responses are very heavy, that might be a problem.
Preacher
Preacher
No the event thread is not actually heavy, the scene is being redrawn in another thread (Im using Xith3D so it can't be in the AWT thread). The event thread updates a Quaterion camera and thats it really.

I tracked the slow down to a sleep method in the main loop, which sleeps for way to long, but it only has problems when im conrolling the camera using the mouse. So i presume its something to do with threading issues.
OrangyTang
OrangyTang
Quote:
Original post by Preacher
OK thanks for the time, i'll most likely use JInput although i would like to keep my program portable, i just thought there might be some polling architecture available, maybe something to suggest to java gaming community??

If you use LWJGL then you can poll keyboard, mouse and controller states whenever you want to (in an API thats dead simple, none of that complicated JInput nonsense). Works on windows, linux and mac.

OT.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.