473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Keyboard isn't read

I'm attempting to move a character in Java, hoping to make it into a game, but the keyboard doesn't function. I've looked over all the code, and nothing seems to be wrong. I'm about to give up. Can anyone help?
Expand|Select|Wrap|Line Numbers
  1. InputManager.java
  2. import java.awt.*;
  3.  
  4. //...
  5.  
  6. public class InputManager implements KeyListener, MouseListener,
  7.     MouseMotionListener, MouseWheelListener{
  8.  
  9. //...
  10.  
  11.     public InputManager(Component comp){
  12.         //...
  13.     }//ends Imput Manager constructor
  14.  
  15. //...
  16.  
  17.     public void clearMap(GameAction gameAction){
  18.         for(int i=0;i<keyActions.length;i++){
  19.             if(keyActions[i]==gameAction){
  20.                 keyActions[i]=null;
  21.             }
  22.  
  23.         }
  24.         gameAction.reset();
  25.  
  26.     }//ends clearMap
  27.  
  28.     public List getMaps(GameAction gameCode){
  29.         ArrayList list = new ArrayList();
  30.         for(int i=0;i<keyActions.length;i++){
  31.             if(keyActions[i]==gameCode){
  32.                 list.add(getKeyName(i));
  33.             }
  34.         }
  35.         for(int i=0;i<mouseActions.length;i++){
  36.             if(mouseActions[i]==gameCode){
  37.                 list.add(getMouseName(i));
  38.             }
  39.         }
  40.         return list;
  41.     }//ends getMaps
  42.  
  43.     public void resetAllGameActions(){
  44.         for(int i=0;i<keyActions.length;i++){
  45.             if(keyActions[i]!=null){
  46.                 keyActions[i].reset();
  47.             }
  48.         }
  49.         for(int i=0;i<mouseActions.length;i++){
  50.             if(mouseActions[i]!=null){
  51.                 mouseActions[i].reset();
  52.             }
  53.         }
  54.  
  55.     }//ends resetAllGameActions
  56.  
  57.     public static String getKeyName(int keyCode){
  58.         return KeyEvent.getKeyText(keyCode);
  59.     }//ends getKeyName
  60.  
  61. //...
  62.  
  63.     private GameAction getKeyAction(KeyEvent e){
  64.         int keyCode=e.getKeyCode();
  65.         if(keyCode<keyActions.length){
  66.             return keyActions[keyCode];
  67.         }
  68.         else { 
  69.             return null;
  70.         }
  71.     }//ends getKeyAction
  72.  
  73. //...
  74.  
  75.     public void keyPressed(KeyEvent e){
  76.         GameAction gameAction=getKeyAction(e);
  77.         if(gameAction!=null){
  78.             gameAction.release();
  79.         }
  80.         e.consume();
  81.     }//ends keyPressed
  82.  
  83.     public void keyReleased(KeyEvent e){
  84.         GameAction gameAction=getKeyAction(e);
  85.         if(gameAction!=null){
  86.             gameAction.release();
  87.         }
  88.         e.consume();
  89.     }//ends keyReleased
  90.  
  91. //...
  92.  
  93. }//ends InputManager
  94.  
  95. // and more...
  96.  
Nov 20 '08 #1
1 1300
r035198x
13,262 8TB
Did you add the KeyListener to some component?
Nov 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Michael Bendzick | last post by:
Is there a simple way in python to read a keyboard scan code? I'm working on a shell script that interfaces with a proprietary keyboard device (extra buttons) and need to be able to distinguish...
1
by: Scott Shaw | last post by:
Hi all, I was wondering if you could help out with this problem that I am having. What I am trying to do is detect keyboard input in a while loop without halting/pausing the loop until the key is...
9
by: Marek Mand | last post by:
How to use generated keyboard events? What I am trying here to do is in onkeyup event handler http://www.hot.ee/idaliiga/braggart/createEventTest.htm generate a (shift)TAB keydown so the...
8
by: Nolan Martin | last post by:
Is it just me or are there no good librarys out there to access the keyboard or mouse? I have been looking around for a while now and can only find ones that are bundled with a bunch of other...
0
by: rs | last post by:
Hi guys, I am trying to read from a USB keyboard using vb.net and HID classes. the USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and is detected in device manager as...
2
by: rs | last post by:
Hi guys, I am trying to read from a USB keyboard using vb.net and HID classes. the USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and is detected in device manager as...
7
by: jpierson | last post by:
Hi, I am tryin to create a keyboard hook that sends the keystroke ctrl + pause/break. I haven't used keyboard hooks before so I'm not too sure how to use them public int MyKeyboardProc(int...
1
by: pinkfloydhomer | last post by:
I am writing a curses application, but the getch() does not seem to give me all I want. Of course, if I press "d", it returns an ord("d") and so on. But I want to be able to detect whether alt,...
3
by: NaN | last post by:
I've been trying to use _kbhit() but it didn't do what I thought it would from books, "Detects whether a keypress is available for reading." Herbert Schildt says, "If the user has pressed a key,...
8
by: BD | last post by:
How can I duplicate the behavior of the operating system shortcut keys in my application? For example, my windows form has 5 controls (textboxes), the operating system will pickup which control...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.