Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Key Detection not working on laptop  (Read 1460 times)
0 Members and 1 Guest are viewing this topic.
Offline Hazzy

Senior Newbie





« Posted 2011-11-16 11:33:41 »

I followed the tutorial on http://zetcode.com/tutorials/javagamestutorial/movingsprites/ pretty much line for line but I have this weird bug I just can't fix.
My little program runs fine on my computer and I can move things around on the screen, but when I move to my laptop with the same program - everything works fine except the key detection.

I've tried debugging it like so and nothing happens at all.
1  
2  
3  
4  
   public void keyPressed(KeyEvent e) {
      System.out.println(1);
      player.keyPressed(e);
   }


This problem only exists on my laptop and works fine on other computers.
My laptop has JDK/JRE up to date and now I have no other solutions to try but to post here.
Offline Fokusas

Senior Member


Medals: 3
Projects: 1



« Reply #1 - Posted 2011-11-16 11:49:38 »

If I am correct then only if your program has focus then it can catch events.
By the way does your laptop has Linux OS ? It can sometimes be pain in ass to find and fix what's work for windows but don't work for Linux Cheesy
Offline Hazzy

Senior Newbie





« Reply #2 - Posted 2011-11-16 12:01:57 »

Yup, my canvas is definitely focused.
I mean it works fine on my desktop and for everybody else, so why only does it not work on my laptop? :/

Both on Windows btw.
I originally started with Linux but that just had a complete mind of its own in terms of Java so I moved back to Windows.

I'm going to try out some small Java games around here and see if it happens with them too.

Edit:
Okay, I pretty much give up. Java has annoyed me constantly on how a simple program can act completely different on other OSs and computers.
I just started looking into libgdx and I'm fairly impressed by it, so I think I'll be sticking with it. Was a little scary at first making the jump but it's easier than I thought! Tongue
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2011-11-16 14:25:14 »

I have experienced that problem with my JDoodle Jump, several people told me they can't control with the keyboard. The solution: requestFocusInWindow() Smiley

EDIT: LibGDX is an OpenGL library. You were using AWT. Two completely different graphics systems. It is best to learn the low levels of OpenGL instead of jumping to a really high level library like LibGDX that does everything for you behind the scenes Wink

Offline Hazzy

Senior Newbie





« Reply #4 - Posted 2011-11-16 15:34:44 »

I have experienced that problem with my JDoodle Jump, several people told me they can't control with the keyboard. The solution: requestFocusInWindow() Smiley

EDIT: LibGDX is an OpenGL library. You were using AWT. Two completely different graphics systems. It is best to learn the low levels of OpenGL instead of jumping to a really high level library like LibGDX that does everything for you behind the scenes Wink
Honestly I have to say - I love you.
It worked. lol
Thanks a bunch Smiley

Now I can finally continue programming games in work when I have nothing else better to do.
I'm still looking into LibGDX but I think I'll learn better where I can actually play around with things and relate to. I didn't go straight for OpenGL because I thought that it only deals with 3D stuff? (Feel free to put me straight)
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #5 - Posted 2011-11-16 22:03:42 »

@ra4king:

does your solution also solve key listening problems on linux?
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2011-11-17 00:35:32 »

@Hazzy
OpenGL is 2D and 3D.

@h3ckboy
I do believe so but I have not tested it on Linux Sad

Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #7 - Posted 2011-11-17 04:31:22 »

@ra4king, In Linux, I tried your jdoodle jump thing and get a java message saying "Error extracting sounds!", If I click OK the message comes right back up, over and over.  The only way to stop it is to close the tab the applet is in.  So, yea that's as far as I can get.

@h3ckboy, if you're looking for a linux fix for the keyboard you can find the RepeatingReleasedEventsFixer class here: http://tech.stolsvik.com/2010/05/linux-java-repeats-released-keyevents.html  The only alteration you need to do to your existing code is add:
1  
new RepeatingReleasedEventsFixer().install();
in the init() or main().

I actually found it last night (read: early this morning) after 3 hours of trying to figure out why my character was firing off shots at random while I was holding down the space bar to select the velocity.  Thinking my code was wrong somewhere and creating premature release events, I was trying stupid things to try and fix the issue before realizing that the pressed and released events were in a different order than what I had thought.   For a change, this bug wasn't my fault!   Grin
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2011-11-17 04:58:09 »

@gbeebe
That message will pop up for each sound file that cannot be loaded. The error that you showed me means that either your Linux OS or the JRE for that Linux OS don't support little-endian sounds. The only way to fix this would be to make big-endian sounds but that would take up too much space. For now, I'll make it so it tells you sounds are not supported on your machine and continue to play the game without sounds.

Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #9 - Posted 2011-11-17 05:09:34 »

I knew the difference between big and little-endian, as a Linux developer you're kinda forced to.  But i never realized that sound files were that way too.  I wonder if a fix would be as simple as allocating memory the same size as the sound data and copy it over backwards and use it instead of the origional.
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.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!