Object Movement with Key Events

Hi everybody!
Im trying to move an object over the screen with keyboard buttons. The problem I have come across with is that I would like to use the right button to move right, up button to move forward, etc. but I cant push, for example, right and up buttons at the same time to make a diagonal movement. How can I solve this?
Thank you and regards.

I added key events to a sequence and than check them in the program.
Something like this:
class Car extends CustomNode {
    var keys:KeyCode[];
    public override function create(): Node {
        ImageView {
            transforms: [ Translate{ x: bind x, y: bind y }, Rotate{ angle: bind direction}]
            x: -w
            y: -h
            image: Image { url: "{__DIR__}car.png"}
            onKeyPressed: function( e: KeyEvent ) {
                insert e.code into keys;
                if(e.code == KeyCode.VK_UP){
                    ds = 2.0;
                }else if(e.code == KeyCode.VK_DOWN){
                    ds = -2.0;
                }else if(e.code == KeyCode.VK_LEFT){
                    da = -1.0;
                }else if(e.code == KeyCode.VK_RIGHT){
                    da = 1.0;
            onKeyReleased: function( e: KeyEvent ) {
                delete e.code from keys;
    public function move(){
          // check keys
}

Similar Messages

  • Why when I move a midi event in the piano roll the film does not move with this event?

    LOGIC X 10.0.3. Why when I move a midi event in the piano roll the film does not move with this event?

    Film? Have you dropped a movie file into your Logic project as well? You need to be a little clearer.

  • Change margins + object move with margins

    Hello!
    We have a catalogue with 300+ pages!
    Margins size for that catalogue are:
    Top: 18 mm
    Bottom: 18 mm
    Indise: 12,7mm
    Outside: 12.7 mm
    Margins Inside and outside must to be change to 20 and 15 mm
    After i change the margins, the objects(incl. contet, tables, text.... etc) is not move with new margins size!
    Enable Layout adjusment.. it is not working like I want.
    How can i change Margins and all object to move with new margins size?
    Thank you in advance!

    If the objects are not currently snapped to guides they will not move reliably. If they are all athe same distance from the current margins, however you can, with Layout Adjustment off, change the margins so they snap, then enable layout adjustment and change the margins to where you really want them.
    Other than that, you need to do your moving object-by-object. If they all need to move the same amount it's probably scriptable, and you should ask in the scripting forum for help: InDesign Scripting

  • Help with key event

    hi everyone i need some help. i have to write an java application thatcreates a panel with three labels and three key events to call upon different methods. i try to creat a JFrame but have problems. anyone can help?
    Thanks

    public class MyClass extends JFrame{
    public MyClass(){
    getContentPane().add( new Label("One") );
    getContentPane().add( new Label("Two") );
    getContentPane().add( new Label("Three") );
    setSize(400,400);
    setVisible(true);
    public static void main(String[] args){
    MyClass myclass = new MyClass();
    public static void main is the starting point of a program.
    When the frame is created using
    MyClass myclass = new MyClass();
    The control goes to the constructor where you can add three labels.
    You can add three methods to MyClass and implement KeyListener in MyClass to build upon it.

  • Probelm with key events

    Hi all
    I am trying to open a swing form from a menu on a Frame object
    On the frame I have a Canvas3D
    everything is going well the canvas3d read my key events and I can walk gladly in my universe
    untill I am opening JFrame and do some stuff on it (changeing values in text fields)
    Hiding the Jframe and trying to keep moveing in my universe is not working any more any ideas???

    I checked it more closly and found out that the I do get the events and the behvior do act on them but I see nothing on the screen help....

  • JTree traversal with key events

    I am looking for any classes available for traversing nodes in Jtree based on the input given through keyboard matching with nearest name in the tree being displayed. This is similar to the feature we have in windows explorer where based on the name we type it selects the nearest node in the tree taking into consideration the expanded paths.
    Thank you in anticipation,
    Srikanth

    What exactly you want to do.
    Have a look at my code, this is what I did a while ago. This may a good start for you.
    tree.addKeyListener(new java.awt.event.KeyAdapter() {
             public void keyPressed(KeyEvent e) {
                tree_KeyReleased(e);
        * JTree Key Released Functionality
        * @param e KeyEvent
       private void tree_KeyReleased(KeyEvent e) {
          try {
          MouseEvent me = new MouseEvent(tree, MouseEvent.MOUSE_RELEASED, 0, 0, 0, 0, 0, false);
          int keyCode = e.getKeyCode();
          // Get the Tree Path
          TreePath selPath = tree.getSelectionPath();
          if (keyCode == e.VK_DELETE) { //KeyCode - 127
             removeSelectedNode();
          else if (keyCode == e.VK_ADD) { // Key Code - 107
             tree.expandPath(selPath);
          else if (keyCode == e.VK_SUBTRACT) { // Key Code 109
             tree.collapsePath(selPath);
          else if (keyCode == e.VK_ENTER) {
             tree_mouseReleased(me);
          else {
          } catch (NullPointerException ex) {
          //System.out.println("Null");
       }

  • Start and stop movie with key press

    Can anyone please tell me how to do this?
    I'm very new to flash.
    Thankyou

    Place this code in the timeline that you are trying to control--pressing and releasing a key will play/stop depending on which mode it is currently in.
    stop();
    var isPlaying:Boolean = false;
    stage.addEventListener(KeyboardEvent.KEY_UP, keyUsed);
    function keyUsed(event:KeyboardEvent)
    if (isPlaying){
              stop();
         } else {
              play();
      isPlaying = !isPlaying;
    If you have other questions, try to anticipate what you might be asked and include those details.

  • How can I get around Javascipt issue with keyboard events?

    Javascript issue: keydown, keypress, keyup events cause quick search to initiate with the division key on the keypad and slash key on the keyboard. I am trying to program a graphic representation of a 10 key pad and the division (/) sign is problematic for roll over and processing based on key events. How can I get around this? further notes: Safari also has problems with key events and the division key(s) but no search function connected. Thankyou for time and attention

    A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

  • BizTalk 2006 Event Log Warnings - Cannot insert duplicate key row in object 'dta_MessageFieldValues' with unique index 'IX_MessageFieldValues'.

    We have been seeing the following 'warnings' in the event log of our BizTalk machine since upgrading to BTS 2006. They seem to occur randomly 6 or 8 times per day.
    Does anyone know what this means and what needs to be done to clear it up? we have only one BizTalk server which is running on only one machine.
    I am new to BizTalk, so I am unable to find how many tracking host instances running for BizTalk server. Also, can you please let me know that we can configure only one instance for one server/machine?
    Source: BAM EventBus Service
    Event: 5
    Warning Details: Execute batch error. Exception information: TDDS failed to batch execution of streams. SQLServer: bizprod, Database: BizTalkDTADb.Cannot insert duplicate key row in object 'dta_MessageFieldValues'
    with unique index 'IX_MessageFieldValues'. The statement has been terminated..

    Other than ensuring that there exists a separate and single tracking host instance, you're getting an error about duplicate keys.. which implies that you're trying to Create a BAM Activity twice with the same data.
    I suggest you have a in-depth examination of the BAM (TPE or API) associated with the orchestration. In TPE ensure that the first binding you select is the "Instance Id" or "Message Id" before going ahead to map the ports or others.
    Regards.

  • Help with understanding key event propagation

    Hello,
    I am hoping someone can help me understand a few things which are not clear to me with respect to handling of key events by Swing components. My understanding is summarized as:
    (1) Components have 3 input maps which map keys to actions
    one for when they are the focused component
    one for when they are an ancestor of the focused component
    one for when they are in the same window as the focused component
    (2) Components have a single action map which contains actions to be fired by key events
    (3) Key events go to the currently focused component
    (4) Key events are consumed by the first matching action that is found
    (5) Key events are sent up the containment hierarchy up to the window (in which case components with a matching mapping in the WHEN_IN_FOCUSED_WINDOW map are searched for)
    (6) The first matching action handles the event which does not propagate further
    I have a test class (source below) and I obtained the following console output:
    Printing keyboard map for Cancel button
    Level 0
    Key: pressed C
    Key: released SPACE
    Key: pressed SPACE
    Level 1
    Key: pressed SPACE
    Key: released SPACE
    Printing keyboard map for Save button
    Level 0
    Key: pressed SPACE
    Key: released SPACE
    Level 1
    Key: pressed SPACE
    Key: released SPACE
    Printing keyboard map for Main panel
    Event: cancel // typed SPACE with Cancel button having focus
    Event: save // typed SPACE with Save button having focus
    Event: panel // typed 'C' with panel having focus
    Event: panel // typed 'C' with Cancel button having focus
    Event: panel // typed 'C' with Save button having focus
    I do not understand the following aspects of its behaviour (tested on MacOSX although I believe the behaviour is not platform dependent):
    (1) I assume that the actions are mapped to SPACE since the spacebar clicks the focused component but I don't explicitly set it?
    (2) assuming (1) is as I described why are there two mappings, one for key pressed and one for key released yet the 'C' key action only has a key pressed set?
    (3) assuming (1) and (2) are true then why don't I get the action fired twice when I typed the spacebar, once when I pressed SPACE and again when I released SPACE?
    (4) I read that adding a dummy action with the value "none" (i.e. the action is the string 'none') should hide the underlying mappings for the given key, 'C' the my example so why when I focus the Cancel button and press the 'C' key do I get a console message from the underlying panel action (the last but one line in the output)?
    Any help appreciated. The source is:
    import javax.swing.*;
    public class FocusTest extends JFrame {
         public FocusTest ()     {
              initComponents();
              setTitle ("FocusTest");
              setLocationRelativeTo (null);
              setSize(325, 160);
              setVisible (true);
         public static void main (String[] args) {
              new FocusTest();
    private void initComponents()
         JPanel panTop = new JPanel();
              panTop.setBackground (java.awt.Color.RED);
    JLabel lblBanner = new javax.swing.JLabel ("PROPERTY TABLE");
    lblBanner.setFont(new java.awt.Font ("Lucida Grande", 1, 14));
    lblBanner.setHorizontalAlignment (javax.swing.SwingConstants.CENTER);
              panTop.add (lblBanner);
              JPanel panMain = new JPanel ();
              JLabel lblKey = new JLabel ("Key:");
              lblKey.setFocusable (true);
              JLabel lblValue = new JLabel ("Value:");
    JTextField tfKey = new JTextField(20);
    JTextField tfValue = new JTextField(20);
    JButton btnCancel = new JButton (createAction("cancel"));     // Add a cancel action.
    JButton btnSave = new JButton (createAction("save"));          // Add a sve action.
              panMain.add (lblKey);
              panMain.add (tfKey);
              panMain.add (lblValue);
              panMain.add (tfValue);
              panMain.add (btnCancel);
              panMain.add (btnSave);
              add (panTop, java.awt.BorderLayout.NORTH);
              add (panMain, java.awt.BorderLayout.CENTER);
    setDefaultCloseOperation (javax.swing.WindowConstants.EXIT_ON_CLOSE);
    // Add an action to the panel for the C key.
              panMain.getInputMap (JComponent.WHEN_IN_FOCUSED_WINDOW).put (KeyStroke.getKeyStroke (java.awt.event.KeyEvent.VK_C, 0), "panel");
              panMain.getActionMap ().put ("panel", createAction("panel"));
              // FAILS ???
              // Add an empty action to the Cancel button to block the underlying panel C key action.
    btnCancel.getInputMap().put (KeyStroke.getKeyStroke (java.awt.event.KeyEvent.VK_C, 0), "none");
    // Print out the input map contents for the Cancel and Save buttons.
    System.out.println ("\nPrinting keyboard map for Cancel button");
    printInputMaps (btnCancel);
    System.out.println ("\nPrinting keyboard map for Save button");
    printInputMaps (btnSave);
              // FAILS NullPointer because the map contents are null ???
    System.out.println ("\nPrinting keyboard map for Main panel");
    // printInputMaps (panMain);
    private AbstractAction createAction (final String actionName) {
         return new AbstractAction (actionName) {
              public void actionPerformed (java.awt.event.ActionEvent evt) {
                   System.out.println ("Event: " + actionName);
    private void printInputMaps (JComponent comp) {
         InputMap map = comp.getInputMap();
         printInputMap (map, 0);
    private void printInputMap (InputMap map, int level) {
         System.out.println ("Level " + level);
         InputMap parent = map.getParent();
         Object[] keys = map.allKeys();
         for (Object key : keys) {
              if (key.equals (parent)) {
                   continue;
              System.out.println ("Key: " + key);
         if (parent != null) {
              level++;
              printInputMap (parent, level);
    Thanks,
    Tim Mowlem

    Use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.
    1) In the Metal LAF the space bar activates the button. In the Windows LAF the Enter key is used to activate the button. Therefore these bindings are added by the LAF.
    2) The pressed binding paints the button in its pressed state. The released binding paint the button in its normal state. Thats why the LAF adds two bindings.
    In your case you only added a single binding.
    3) The ActionEvent is only fired when the key is released. Same as a mouse click. You can hold the mouse down as long as you want and the ActionEvent isn't generated until you release the mouse. In fact, if you move the mouse off of the button before releasing the button, the ActionEvent isn't even fired at all. The mouse pressed/released my be generated by the same component.
    4) Read (or reread) the [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html#howto]How to Remove Key Bindings section. "none" is only used to override the default action of a component, it does not prevent the key stroke from being passed on to its parent.

  • Why doesnt the smart filter mask move with the smart object?

    OMG Why doesnt the smart filter mask move with the smart object?  Yikes Way PITA

    If you look at the other tread about transform Again and smart Object layers you will find I found there seems to be two flavors of Transform and some bazar behaviors when it come to smart object layers. http://forums.adobe.com/message/4611500#4611500
    However for this problem here I think I can not show you how to do it.
    First target the smart filters Mask.  In fact so you can see what is happening Alt+Click on it so Photoshop displays the mask rather then the the composit image.  Then  use Ctrl+T free transform then just for a test hold down the Ctrl and the Alt keys and drag in a cornor to constrain and srink the Mask thee release the keys and press enter to commit the transform.
    Next target the smart object layer then use the short cut Ctrl+Shift+T (Transform Again) on a PC the smart object layer will be transformed to match the filter mask transform.

  • Iphoto events showing with key photo of a palm tree in gray?

    iphoto events showing with key photo of a palm tree in gray? Also indicates no photos but there are photos within the event??

    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In early versions of Library Manager it's the File -> Rebuild command. In later versions it's under the Library menu.)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  
    Regards
    TD

  • Looking for answer keys for "Object First with Java"

    Where can I find a book with anwser keys for the book " Object First with Java" Third Edition?

    zxcvbnm wrote:
    Where can I find a book with anwser keys for the book " Object First with Java" Third Edition?This ought to be an interesting thread. :)

  • I am attempting to update from iMovie 9 to iMovie 10. I have many movies with iMovie 9. Yet, on iMovie 10, when I press "update projects and events", it states "iMovie could not find any projects or events to update". What do I do?

    I am attempting to update from iMovie 9 to iMovie 10. I have many movies with iMovie 9. Yet, on iMovie 10, when I press "update projects and events", it states "iMovie could not find any projects or events to update". Somehow it doesnt' see all the movies I have on iMovie 9 library.  What do I do?

    I'm dealing with this same issue. At one point, it did recognize the Update function but then said it could not import the cache.mov and plist files which apparently means that imovie 10 can't see any of these past events. I can't figure it out.

  • Movement with arrow keys

    When I first put this code in, it worked.  Now it doesn't.  Does anyone have any ideas as to how to fix it?
    var playerMc:player = new player();
    addChild(playerMc);
    playerMc.x=520;
    playerMc.y=390;
    var speed:Number = 10;
    var left:uint = 37;
    var up:uint = 38;
    var right:uint = 39;
    var down:uint = 40;
    import flash.events.KeyboardEvent;
    stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
    function keyDownListener(e:KeyboardEvent) {
        if (e.keyCode==left){
      playerMc.x = playerMc.x - 10
    if (e.keyCode==up){
      playerMc.y = playerMc.y - 10;
    if (e.keyCode==right){
      playerMc.x = playerMc.x + 10;
    if (e.keyCode==down){
      playerMc.y = playerMc.y + 10;

    That's the thing, it did work and now it doesn't.  This is all the code I have for the scene.  I don't think any of it is interferring.  But nothing happens when
    I hit the arrow keys.  And this was my third mover code I tried and this one finally worked.
    //variables
    var doorslocked:Boolean = true;
    //end variables
    //vendor count
    var vendorcount = 0;
    if (vendorcount == 7){
    gotoAndStop (8);
    //end vendor count
    // timer
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    var secs:Number = 0;
    var mins:Number = 9;
    var sec_t:String;
    var min_t:String;
    var my_timer:Timer = new Timer(1000);
    my_timer.addEventListener(TimerEvent.TIMER, timerHandler);
    my_timer.start();
    function timerHandler(event:TimerEvent):void
    if (secs == 0 || secs <= 0) {
      if (mins == 0) {
       my_timer.stop();
       trace("Countdown is finished.");
       return;
       gotoAndStop (9);
      } else {
       --mins;
       secs = 59;
    } else {
      --secs;
    sec_t = (secs<10) ? "0"+String(secs) : String(secs);
    min_t = (mins<10) ? String(mins)+":" : String(mins)+":";
    time.text = String(min_t+sec_t);
    //end timer
    //mover
    var playerMc:player = new player();
    addChild(playerMc);
    playerMc.x=520;
    playerMc.y=390;
    var speed:Number = 10;
    //end mover
    //test keys
    var left:uint = 37;
    var up:uint = 38;
    var right:uint = 39;
    var down:uint = 40;
    import flash.events.KeyboardEvent;
    stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
    function keyDownListener(e:KeyboardEvent) {
        if (e.keyCode==left){
      playerMc.x = playerMc.x - 10
    if (e.keyCode==up){
      playerMc.y = playerMc.y - 10;
    if (e.keyCode==right){
      playerMc.x = playerMc.x + 10;
    if (e.keyCode==down){
      playerMc.y = playerMc.y + 10;
    //end testing
    //vendors
    var vendor_local:Number = Math.random()*3;
    var vendor_floral:Number = Math.random()*3;
    var vendor_music:Number = Math.random()*3;
    var vendor_decor:Number = Math.random()*3;
    var vendor_cake:Number = Math.random()*3;
    var vendor_photo:Number = Math.random()*3;
    var vendor_video:Number = Math.random()*3;
    //end vendors

Maybe you are looking for

  • Can Captivate 5 allow user to answer all questions and then submit?

    Good morning, I am doing a management comparision so our team can select our standard quizzing tool.  I am comparing Quizmaker by Articulate and Captivate.  What we are not going to do is say; "this tool is our standard and we will always use it."  W

  • KIMYONG : OAframework MDS reporsitory에서 OA page 찾는방법

    PURPOSE 이 노트는 JRD repository 에 import된 page이름을 찾고자 할때 사용하는 SQL입니다. Explanation The script below can be used to search for any page name REM START OF SQL REM REM Script to list out the data from the MDS repository for SS Fwk application REM Only run u

  • How did symatec virus ad get in my email

    Sent myself an email from work to home with a large file attachment. When I opened it at home to read the file, I saw an advertisement for symatec virus protection. How the heck did that happen? Should I toss the whole thing in the trash? I think tha

  • How to Parse CLOB varialbe in Coldfusion 9

    Hi, I am trying to parse CLOB variable in Coldfusion 9. Can you please help. Below is the peice of code I wrote but getting exception( Encountered "(. Incorrect Select Statement, Expecting a 'FROM', but encountered '(' instead, A select statement sho

  • Desired date in planned orders

    Hi all! I used heuristics SAP_PP_002 for creation planned order (AI) from sales order (BM). APO show message Order &1 with source &2 created late on &3; desired date &4 That I need to do, that desired date planned order (AI) - Requested Delivery date