KeyListener not working?

I have been working on a game for a while and have been using keyListener. It always worked but lately keyPressed() is not always called. I used output statements to show which key function is being called. keyReleased() always works for some reason. I was just wondering if anyone could help me out with this weird problem. Thanks!

Edit: I am using JFrame by the way

Can you put in your code so we can see it?

Here is my main class where the input is taken.

http://pastebin.java-gaming.org/d1b0833984a17

Allright Yay,

first thing I would like to say: I think this declaration method of variables won´t get you far. Wouldn´t it be easier to store everything in an array or a list ?
Also, you should think about dezentralisation. If you want us to go through this class, we´ll have a problem since you´ve got so much stuff in this class which makes it very hard to understand what exactly you´re doing right now.
Now, to your problem:
I had a quick look on it and I might have an Idea. I think you canvas might be unfocused yet. Just change the line addKeyListener(this) to frame.addKeyListener(this).
If it works then, you might to request focus for the canvas in order to get the key listener work on the Canvas. I think there was a method in the Frame class thatfor, else maybe in the canvas class. I can´t look it up now but if you google something like “Java canvas request focus” you should find tons of solutions.
I hope this helps you.

Best regards,
Major

;D
Yup that did it! thanks a lot!