Handling keyboard events in applets?! Possible?!

Hello,
I wrote a little game that uses keyboard handling events. It is an applet that can also standalone as an application. When i run the program as a standalone application, it handles keyboard inputs fine. ie...i can press the left and right arrow keys and something happens.
But when i run my program as an applet in a web browser, the applet starts up correctly but does not handle any keyboard events. It only handles mouse events. For instance, if i press the up and down arrow keys, the browser window scrolls up and down!!! And the up and down arrow keys have a specific purpose in my applet.
QUESTION: how do i get my applet to accept keyboard inputs such as UP,DOWN, LEFT, RIGHT?

Hmm something went wrong w/ my post so i hope this doesnt show up twice.
Hey thanks a lot for helping me out. The applet/application is large so here is the main() method and the keyboard event handling class code. My question is how come the keyboard events get properly handled when i run it as a standalone application, but keyboard events go to the browser when i run it as an applet? I would post my entire code but it's over 1000 lines and spread out over 8 files. hehehe.
Here is main():
  public static void main(String[] args)
      MyProgram applet = new MyProgram();
      applet.isStandalone = true;
      JFrame frame = new JFrame();
      frame.setTitle("Physics: Kinematics");
      frame.getContentPane().add(applet, BorderLayout.CENTER);
      applet.init();                        // initialize the applet inside frame
      applet.addKeyListener(kbHandler);     // kbHandler is a keyboard handling object
      applet.start();
      frame.setSize(APPLETWIDTH,APPLETHEIGHT);
      Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
      frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
      frame.setVisible(true);
      // private inner class to terminate the Application when frame closes
      frame.addWindowListener(
        new WindowAdapter()
            public void windowClosing(WindowEvent e)
                System.exit(0);
      frame.show();
   }"kbHandler" is the keyboard event handling object. It gets initialized in the applet.init() method.
kbHandler = new BMkeyboardHandler();And here is the keyboard event handling code:
// ===== keyboard event handler ===========
   private class BMkeyboardHandler implements KeyListener
        public void keyPressed(KeyEvent e)
            pushedKey = e.getKeyCode();
            // General administrative key actions
            if(pushedKey == KE.VK_H)
                actionArea.toggleHelpMenu();
                actionArea.repaint();
            else if(pushedKey == KE.VK_C)
                actionArea.toggleCtrlMenu();
                actionArea.repaint();
     }So there it is. Again, the program handles events fine as a standalone application. But running it as an applet in a browser (and even the appletviewer) doesnt let me handle keystrokes.

Similar Messages

  • Handling Keyboard Events

    Hi:
    Below is an Air application in which I am trying to catch keyboard events.
    I do catch it once. Subsequently when I try to catch the events, sometimes I must click on the canvas
    to refocus. Sometimes even this does not work. When I choose an option in DropDown list then the handler
    also stops working. Is there something missing in my envent Handler?
    Please advise and thanks for reading and helping.
    <?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute" windowComplete="windowComplete();"> <mx:ApplicationControlBar id="dockedBar" dock="true" paddingLeft="0" paddingRight="0"> <mx:ComboBox dataProvider="{stats}" id="statsC" change="statsChangeEvt(event)" /></mx:ApplicationControlBar>
    <mx:Array id="stats"> <mx:Object label="Option 1"/> <mx:Object label="Option 2"/></mx:Array><mx:Script> <![CDATA[ import mx.controls.Alert; private function windowComplete():void{stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);} public function handleKeyDown(event:KeyboardEvent) :void{Alert.show("Key pressed");} private function statsChangeEvt(event:Event):void { Alert.show("Stats Changed")};]]></mx:Script> </mx:WindowedApplication>

    Try listening to the keyDown event in the capture phase.
    addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown, true).
    ComboBox stops the propogation of the event if it is something that it handles. This is why you don't get it in the bubble phase.
    Jason

  • No keyboard Events on a Window

    Hello Java community,
    I can't understand why, if you build a simple Window (not a Frame), all keyboard Events are simply ignored !! Everything acts as if the Window can't get the focus, because no LOST_ or GOT_ FOCUS events are triggered. This means that you can't handle keyboard events with a Window and therefore a Textfield will not work (however it still receive mouse events ??). BUT it perfectly works with a Frame , which extends from Window! Strange isn't it ?
    I've heard on other forums that , to be eligible for focus a Window must have:
    - its owner Frame (the one given in the constructor) :
    * displayed on screen,
    * containing a focusable component.
    - itself, containing a focusable component.
    thus i respect theses limitations, i still can't get any keyboard events
    pleaze help, i am writing a text area component and without keyboard events ...

    Thanks for the answers BUT,
    I have already read the javadoc in every ways and I am sure I respect perfectly all the conditions to have my WINDOW focusable.
    No, there is another problem, a strange one. In fact, my program works fine under Windows I can type characters into my Textfields but once executed under Linux : no keyboard events! Therefore, no character type allowed. I display in the console, all events that are incomming into my Window, and ALL events are ok (mouse, windows..) except keyboards ones. When I press a key, nothing appears in my console, that's why I think keyboards events are caught and not dispatched to the Window.
    I noticed an interresting fact when using my app in Applet. For example, I launched my application with Mozilla (Netscape 4, JRE 1.1). I displayed an empty Window on screen, when my mouse passes over it or when I click, the Java console showed me these events. When I try to hit some keyboard keys, nothing except for certain keys such as F, G, D, J and numeric keys. In fact, these keys are shortcuts to some of the System class (F calls Finalization, G=Garbage Collector, D=Debug Mode...). I truely think that on a Window, all keyboard events are send to the console. Another fact that proved me that i was right : I tried my app with JRE 1.2, and when I wanted to type characters into my TextField (which is on my Window), the typed characters appeared in the console !!!!
    A JAVA-experimented person told me to redirect the standard input to my own inputStream... but how ?
    Any ideas of solutions ?

  • How to handle key events in popup component

    Is there any possibility to handle keyboard events after a popup is opened
    requirement : I want to close popup when I press escape key (by default this functionality is present but in some scenarios this is not working ) so explicitly i want to handle key events for popup.
    Thanks,
    Raghavendra.

    in my application header part of the page is common of all page. header.jsff contains comandmenuItem named "proceduralhelp". if I click proceduralhelp a pop up opens .
    in my login page when first time I open popup and press escape popup is not closing.
    rest of the cases after login escpe will cose the popup.
    only on the loginpage that to for the first time it is not closing when pressing up on escape key. (then we click on close button. and once again open the popup in loginpage now if we press escape it works).
    Thanks,
    Raghavendra.

  • Getting keyboard events with Group

    Hi all,
    I'm new to JavaFX and I'm trying to handle keyboard events in a group but it doesn't seem to respond when I press the keyboard.
    As I understand this is because Group doesn't receive the focus. If that is the case, how can I make it receive focus? I tried calling setFocusTraversable(true) and setFocused(true) but both haven't helped.
    If it's not the focus, what is it?
    Thanks!

    Use requestFocus() instead of  setFocused(true).
    Keyboards events work as expected  with a group.
    @Override
        public void start(Stage primaryStage) {
            Button btn = new Button();
            btn.setText("Say 'Hello World'");
            Group root = new Group();
            root.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
                public void handle(KeyEvent event) {
                    System.out.println(event.getCode());
                    event.consume();
            root.getChildren().add(btn);
            Scene scene = new Scene(root, 300, 250);
            primaryStage.setTitle("Hello World!");
            primaryStage.setScene(scene);
            primaryStage.show();
            root.requestFocus();

  • Is it possible to handle multiple events using Jscript for a button in Apex

    Hi,
    I've application wherein in one of the pages for a button, I need to trigger 2 events as: 1. redirect to a new page upon 'click' of the button
    2. display a set of values on 'mouse over' that button.
    I'm able to handle both separately, but not in one button. I would like to know if there is any limitation in Apex that we cant handle multiple events? Currently I've put a text item near the button, and called the Jscript for mouse over event in that as a temporary workaround. Can someone let me know if this is feasible? If not any other alternative to handle this?
    Thanks in advance,
    gsachidh

    Hi Gsachidh,
    well interesting problem you're facinng. Indeed, it can't be specified using the 'Button Attributes' So we have to come up with an workaround.
    A quick en dirty solution would be to specify it with the 'Optional URL Redirect options'. In a normal button, with processing on same page, this would be 'no target'. but in case of additional things to be done this can be used, using an target URL. I used this many times, in example with popUp windows for refreshing the caller object when changes are made. In your case we have to add next to the href an onmouseover event. this can be done with;
    Target set to => URL
    URL - target => javascript:doSubmit('<button_name>');" onMouseOver="javascript:showTooltip('tooltip');"
    Here the " is the key, letting ApEx know the target (href) is doSubmit('<button_name>'), just like when no target would be specified and adding a new javascript event; onMouseOver.
    Although this is a dirty solution in my opinion, it is the best i could come up with. I have another idea in how to do this, that is by adding this event dynamically with javascript with an addEvent. But i don't have an example at the moment for this scenario.
    Simon
    Message was edited by:
    S1M0N

  • ADF Mobile: amx:listView keyboard event handler

    My view needs to accept keyboard input, but does not have an inputText, only a listView. I need to update listItems based on the keyboard input, but cannot add an inputText field to the view. Can I capture keyboard events in the view, the panelPage, or the listView?
    Thanks,
    Mike

    Plzz help :(

  • Help with possible mouseEvent/Keyboard Event problem

    Hi guys, I am having trouble with a game I am creating right now.  The problem seems to lie on mouse / Keyboard event.
    Basically, I have a character that the player can control using the  keyboard arrow keys and it works perfectly fine on its own.  Whenever the game starts,  the player can control the character instantly with the keyboard. Here's the problem now, after I added another page (at frame 1) and created a start game button, those keyboard events  won't start immediately anymore.  The player must click on the stage  again before it works.  Is there any method to solve this?
    Right now, here is my Start button page.
    var start_btn:Start_btn = new Start_btn;
    start_btn.addEventListener (MouseEvent.CLICK, goGame);
    function goGame(event:MouseEvent) {
    gotoAndStop("game"); //The game's frame
    this.removeEventListener(MouseEvent.CLICK,goGame);
    Here's some code for the actual game part.
    stage.addEventListener(KeyboardEvent.KEY_DOWN,keyP  ressed);
    function keyPressed (e:KeyboardEvent) :void {
    //character movement code...like charcter.x++, x-- etc
    Thanks in advance

    How about trying:
         stage.focus = stage;
    in goGame().

  • Keyboard events in borderless windows.

    I have created a borderless window (class JWindow) in order to handle transparency (non-rectangular window). While the whole system seems to work, the keyboard events are not forwarded anymore to components within the borderless window. For example, there is a list in the window that could be browsed using up/down on the keyboard; it is not possible to use the keyboard to browse it anymore now (although the mouse can hopefully still be used).
    I didn't find anything about that in the bugs database. Do someone has an idea?
    Thanks in advance :-)

    Wow, it looks like a ugly hack! But it seems it works despite of a few problems: when I click, it sometimes has some kind of painting loop that lasts until the mouse leaves the window, and when I press a key, the paint events are sent only when the mouse enters/leaves the windows. Very strange, but at least I have somewhere to look. Thanks :-)

  • Disablying keyboard events in a JFrame.

    Hello,
    How is it possible to disable keyboard events for a specific JFrame and then (after a while) enable events again ?
    thank you,
    Rami

    Look at this program, events are send but you can't see the data in the fields.
    import java.awt.*;
    import java.awt.event.*;
    public class Nok extends Frame
    public Nok()
         super();
         setBounds(6,6,400,300);     
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
                   dispose();     
                   System.exit(0);
         setLayout(new GridLayout(4,0));     
         add(new TextField("this is a text field"));
         add(new TextArea("this is a text area"));
         add(new Button("this is a button"));
         setVisible(true);
         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener()
         {     public void eventDispatched(AWTEvent e)
                   System.out.println(""+e);
                   ((KeyEvent)e).consume();
         }   ,AWTEvent.KEY_EVENT_MASK);
    public static void main (String[] args)
         new Nok();  
    Noah
    import java.awt.*;
    import java.awt.event.*;
    public class Nok extends Frame
    public Nok()
         super();
         setBounds(6,6,400,300);     
         addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
                   dispose();
                   System.exit(0);
         setLayout(new GridLayout(4,0));     
         add(new TextField("this is a text field"));
         add(new TextArea("this is a text area"));
         add(new Button("this is a button"));
         setVisible(true);
         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener()
         {     public void eventDispatched(AWTEvent e)
                   System.out.println(""+e);
                   ((KeyEvent)e).consume();
         } ,AWTEvent.KEY_EVENT_MASK);
    public static void main (String[] args)
         new Nok();

  • Can we catch keyboard event triggered by an inputfiled?

    Hi all,
    I have a question here:
    When we are doing the web dynpro abap development, if I want to catch the keyboard triggered by an
    input help and handle it, how can I achieve this?
    e.g.   I have an inputfield on the UI,  if user click "F10" on the keyboard, can I catch this kind of event?
    Thanks and Regards,
    Aaron

    Hi Thomas,
    Yes, I'm trying to acomplish an input help for an inputfield.But, the free programmed value or OVS or dictionary search help can fullfill my needs.Here is the situation:
    I have a inputfield on the UI, and next to that , I have another textview, which should be changed according inputfield. e.g.  the inputfield is a user name, and next to that , is the user id. but we only want the input help for user name. so when user select one row iof the search result table, I want that two fields both filled.
    1. the OVS can't meet my need because I can't change the layout of the search result table, I need a table with a tree in it.
    2. free programmed value help can only send back the value of the inputfield. although maybe I can get the user_id's context attribute name and by hardcoding and send back also the user id. but I don't like hardcoding.
    So, I'm wondering whether I could catch the keyboard event. and handle the F4 help all by myself.
    Do you have some suggestion on this?
    Thanks and Regards,
    Aaron

  • Getting keyboard events on ALV grid

    Hi,
    I have an ALV Grid where it is possible to edit data. If user selects a row and presses delete/cut button with mouse event is triggered and I can access those events in code. Although if user selects a row and presses "Del" or "Ctrl + X" then I can't access those events in code. Is there a way to access keyboard events inside my code?

    Have a look at BCALV_GRID_EDIT -> if you select the first checkbox (p_cell = Update on cell change) then you will find that "data_changed" event can catch the line deletion via the keystrokes described.. in the event in this program, you could get the rows deleted from "rr_data_changed->mt_deleted_rows".
    if p_cell = 'X'.
      call method grid1->register_edit_event
        exporting
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    else.
    Jonathan

  • Javascript error in event handler! Event Type = element [edge.2.0.0.min.js:162]

    I'm doing a little edge project (now in beta version) for my girlfriend (she hates the code), with examples of the animate() method and other functions like setInteval(), but when I run I get the following error in Chrome console:
    Javascript error in event handler! Event Type = element [edge.2.0.0.min.js:162]
    But this library is global for all projects, how is possible that trigger an error?
    Example here:
    https://app.box.com/s/m7nof4al6597gfn47jlu
    Thanks.

    you dont need to import java ease !!
    it's already included in edge animate, remove that yepnope completely your problem will gone
    Zaxist

  • [solved] send keyboard event / key to specific background window?

    Hi!
    So... is this possible / how? I'd like to send keyboard events to a window in the background - maybe even in regular intervals. While I'm dong something else, in another window (or nothing).
    Thx!
    Last edited by whoops (2011-07-21 11:05:44)

    Actually I'm thinking, maybe there is a totally another (better?) way to do what you want. I usually find that automatizing tasks in linux differs very much from the windows experinece, most of the times scripting is the most powerful and easy way of doing things. So if you describe to us what you want to accomplish, maybe some experienced linux gurus would give you some advices that sets you off course from sending keys and mouse events. I used to do that in windows with autohotkey, but now in linux there was no need for that so far ever, except for using system wide abbreviations with autokey.

  • Handling FPM Events in Java WDP

    Hi All,
    I have a requirement for a simple WDPJ iView that responds to the selection of an employee in MSS.
    Is it possible to handle the employee selection event from Business Package for Manager Self-Service (mySAP ERP) from a simple WDPJ iView that is not configured/resgistered as an FPM Self-Service application?
    Can a WDPJ simply handle theses events if the event name is known?
    Cheers,
    Steve

    Steve,
    you may want to check out these links
    Adding custom iview to general info
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/how-toaddacustomWebDynproiViewtotheMSSEmployeeProfile%28ECC+6.0%29
    and check this note 1112733
    Thanks
    Bala Duvvuri

Maybe you are looking for

  • Trying to report bug in SQL Server Replication with sp_MSdetect_nonlogged_shutdown stored procedure

    I've just tried to "Submit Feedback" but the page just gives me an error which means nothing to anyone which says "You are not authorized to submit the feedback for this connection.". Why am I not authorised how do I become authorised etc etc. Anyway

  • Mm01 customised subscreen

    Hi i had created a customised subscreen 1002 and program name saplzzmgd1. after creating this i had gone to spro and select logistics general,in this i selected material master, and then expanded configuring material master, and then executed this  D

  • Iso 7.1 causing really slow texting

    can anyone help me and suggest what i can do regarding slow performance on my 5s, deleted and did a restore as a new phone and the texting worked fine but put my data back on and its back to the way it was running really slow please help

  • Talent Management - Talent Search and Enterprise Search

    Hi All, We are on ECC 6, Portal 7 SP3. We are using Talent Management Business Package. Under Talent Management-> Talent Information, there is an iView called Talent Search(which is based on the Webdynpro ABAP "hrtmc_search"). For this Search functio

  • Modeler start iwth IE7

    Hi, experts, after updating my Internet Explorer to IE7 I can't start the Modeler ( Transaktio RSPLAN -> Modeler). The error-message is :   Application error occurred during request processing.   Details:   com.sap.tc.webdynpro.services.exceptions.WD