NSView subclass and mouse clicks

I wrote a relatively simple program. It's got a single visual component on the window, an NSView subclass with drawing delegated out to another class called Arrow. Anyway, it uses a timer to trigger calls to drawRect which in turn "animates" a layer. I have a 100x100 layer and a velocity & position which get updated each time through depending on how much "real" time has passed. As the layer bounces around the screen, the animation seems smooth and everything looks good. If I start clicking in the window, however, things get wonky. The animation stutters (probably expected) and the position sometimes gets set back to the origin (0,0, bottom left corner of screen). I wonder if there's something I can do to stop mouse clicks from affecting the view, I have no set up anything to use the mouse clicks AT ALL so I don't really know how they can affect anything in the code I wrote. If this isn't enough info to answer the question, I'll post the xcode project.

The end result is going to be a very simple 2d game with maybe 8-10 things on the screen moving around at any one time. My next step is to try out openGL but using these CALayers seemed a lot simpler. However, since you say any event will block, I expect that will happen to opengl as well. I'll dig some more in the examples. It seems I followed the pattern from the crash landing demo (although I'm doing it on the mac itself, not iphone/simulator) to set up the rendering.
When you suggest using core animation, are you talking about just telling it the start/end position and the speed, and letting it handle everything in between? I don't think that will work for my case because eventually I will have to handle mouse/keyboard events to alter the movement in real-time. Am I missing something?
Thanks again for your help.

Similar Messages

  • Recording keystrokes and mouse clicks?

    Greetings,
    I need to be able to make scripts/macros by recording keystrokes and mouse clicks with location.
    Is this possible with Automator?
    Does anyone know of a way program to do this?
    It seems so simple.
    Thanks

    Keyboard shortcuts were often missed.  For example, I tried this sequence many times. 
    0: (setup:  text editor is scrolled to first line and cursor is at the beginning of the first line)
    1: Click on text editor window to focus it.
    2: press SHIFT-DownArrow to move cursor down one line and select the first line
    3: press CMD-X to cut the line.
    Automator never would capture those key strokes. 
    But today I has a break through.  This sequence does work:
    0: (setup:  text editor is scrolled to bottom of the file and the cursor is placed below the last line.)
    1: Click on text editor window to focus it.
    2: press SHIFT-UpArror to move cursor up one line and select the last line.
    3: press CMD-X to cut the line.
    about 70% of the time this did get recorded correctly (I did maybe 3 recordings and one failed to select).  Once it got recorded correctly it worked reliably. 
    So it seems to be able to capture some sequences but not others.  Both sequences work very reliably when I type them but automator can only capture the last sequence. 
    Thanks for the suggestions.  This tool is better than nothing but not anything I would recommend.

  • Mouse over and Mouse Click function

    Hi,
    I have to add a mouse over event and mouse click event in my rectangles that I draw while taking the values from an input file. Now since I am taking rectangle height and width from the input text file as well I also want to take a text value to be shown while moving a mouse over a particular rectangle from my input file. Also when he clicks on that rectangle the height and width of that particular rectangle only should be displayed (re-adjusted).
    Like suppose my input file has 3 fields:-
    Height   Width  Test_To_Show
    10          23         Hello
    20          44         ByeNow When my paint component draws these 2 rectangles and a user moves his mouse over the rectangle he should see text message attached to it:- Like for first row 10, 23 he should see "Hello". In this case when he clicks on this rectangle the picture should read just to show only 10 and 20 as height and width. Now the problem is I am confused where to add the mouse and mouse click event function.
    Some of my code looks like this in paintcomponent method:-
            for(int i=0; i<myobject.size(); i++){
                Coloring fc = myobject.get(i);
                GradientPaint gpi = new GradientPaint(0, 0,c.getColor() , 0, 20, Color.white, true);
                g2d.setPaint(gpi);
                g2d.drawRect(fc.value1, 29, fc.mywidth, 83);
                g2d.fillRect(fc.value1, 29, fc.mywidth, 83);
                                                }Where should I attach the mouse event to g2d object / fc / myobject ? I am not sure since I am using mouseover function for the first time.
    Thanks

    I am planning to add these 2 in my paint component method
                fc.addMouseMotionListener(this);
                fc.addMouseListener(this);and then create 2 functions like this :-
          public void mouseEntered(MouseEvent e) {
                  //I will be reading from a file and then pass the string that I want to show as text while mouse over
                   String s = // takes value from the inpuf file.
                      fc.setText(s);
    public void mouseClicked(MouseEvent e) {
                 //same way reading from the file ... Not sure how I will do this one
                 }Would it be the correct way to do it ? I am doing mouse over functions for the first time so donno much about there usage.
    Thanks

  • Lost keypresses and mouse clicks:  Hardware problem?

    I recently bought an Intel MBP, and I've been noticing strange behaviors with regard to keypresses and mouse (touchpad) clicks getting lost sometimes. The problems I'm having are hard to reproduce intentionally, but I can hear the keypresses and mouse button clicks when I do them, yet nothing happens. While it's possible, that I sometimes am hitting the wrong key, I have been paying closer attention lately to this problem, and of course, the mouse button kinda hard to hit incorrectly. Here are some examples of weird things I encounter:
    If I click in a text field in Safari, sometimes the first keypress (and only the first) will get lost.
    Sometimes, the first keypress I type right after clicking gets lost. For instance, just now, I noticed a typo in the above sentence, so I clicked on the character and hit the Delete key. The cursor was in the right place, but the delete didn't happen. I had to press the key again.
    Sometimes, even when the window for sure has focus and the pointer is squarely pointing to a link, the first click on the link won't take. I have to click it again. Since Safari doesn't have adequate feedback for when you click something, that can get particularly frustrating. Similar things happen with buttons in applications or on the title bar.
    If I'm using an X11 app, and I copy/paste with the clipboard, the touchpad won't respond to movement for 2 or 3 seconds afterward. This is particularly visible with "nedit". I don't think this is an "ignore accidental touchpad input" issue, because this only happens with clipboard actions; other keys don't have this effect. I haven't noticed this with native apps.
    However, I have noticed in X11 and native apps, sometimes, Ctrl/Cmd-C and Ctrl/Cmd-V will be ignored. They're never ignored if I selected the text using the keyboard (shift+arrows), but if I select the text with the mouse and then use the shortcut to copy, the copy/paste sometimes doesn't happen.
    I have noticed that if I am more deliberate about clicks (make sure to hold the button down longer), the probability of losing the event SEEMS to be reduced, but not eliminated. Is there a debounce circuit involved that's causing me trouble?
    This kind of loss of input is unusual to me. I have a number of Windows and Linux PCs, and I've never experienced this sort of thing. I've also used a few Macs at school before I got this one and didn't notice anything weird.
    Can anyone shed some light on this for me? It would seem odd that I should have to modify my keyboard/mouse using behavior when switching to the Mac. If the problem is hardware, how can I prove it? (Perhaps I could boot Knoppix from a CD and mess around a bit.) If the problem is software, is this a case of MacOS trying to second-guess user input?
    Thanks!

    Theosib,
    Apple regularly monitors these boards, but you may never see a response from Apple directly. Assume this is a user to user forum. If you are having a problem with the computer and need a response from Apple call 1-800-APLCARE and speak to customer relations at that office if the technician is not able to satisfy your needs.
    Your problem while not unheard of, is more uncommon than the boards may make you believe.
    Remember, Spotlight is constantly indexing. If your hard drive is overfull, it may take longer for Spotlight to index, thus cause a multitasking delay. If you have many Dashboard widgets, they may all be trying to access the net for updates at once, and again, a delay might happen. I've written a FAQ* about several other factors which may affect Mac OS X speed, which could in theory also affect keyboard input:
    http://www.macmaps.com/Macosxspeed.html
    And of course, you should always check Apple menu -> System Preferences -> Keyboard and Mouse to make sure your input settings are the ones most comfortable for you when using the keyboard. It is possible a repeat rate could cause a delay.
    Edit: I attempted to answer another of your questions here recently with an update:
    http://discussions.apple.com/click.jspa?searchID=-1&messageID=3988468
    Please take a look and see if it answers your question.
    * Links to my FAQs may give me some compensation.

  • External Interface and Mouse Clicks

    I'm new to writing ActionScript.
    I am working in .NET (C#) environment using
    AxShockwaveFlashObjects.
    I am simply trying to react to a mouse click on the Flash
    ActiveX Control.
    I have inserted the code in a layer only used for script:
    import flash.external.ExternalInterface;
    var mouseListener:Object = new Object();
    var boolMouseDown:Boolean = false;
    mouseListener.onMouseDown = function ()
    boolMouseDown = true;
    mouseListener.onMouseUp = function()
    if (boolMouseDown)
    ExternalInterface.call("MouseClicked", "NavigateToURL", "
    http://www.adobe.com");
    boolMouseDown = false;
    Mouse.addListener(mouseListener);
    I get the MouseClick event in my C# code. The problem is that
    I get TWO of the same event ??
    Can someone tell me why or how I should be doing this to get
    only one event.
    Thanks,
    Steve

    Take a look at java.awt.event.MouseAdapter, which implements interfaces MouseListener, MouseMotionListener, MouseWheelListener and EventListener.
    For sample codes on how to use these classes, read through the posts on the Swing forum and you'll find plenty.
    If you have a more specific question, feel free to post back.
    db

  • How do I adjust the system sounds(keyboard and mouse click) in the audio for a software simulation?

    Mouse clicks and keyboard strokes very loud in software simulation, but voice is low. I am using Captivate 7

    Indeed, I would increase the volume of the voice-over. There is a keystroke sound effect within the C:/Program Files/Adobe/Captivate 7/Gallery/Sound Effects folder, but I'm not sure if that one is directly related to the sound effect used by default.

  • AutoSubmit and mouse clicks.

    There seems to be a usability problem when using the autoSubmit feature in ADF Faces. Whenever the user enters a new value in an autoSubmit field and then clicks on some other action component (e.g. a CommandButton, CommandLink, a selectInputText icon, etc.), the autoSubmit for the modified field occurs and the appropriate backing bean is invoked. However, the action component event is not then fired and the user basically has to click again to get the desired action. This behavior is very different when they don't first modify an autoSubmit field where the action event is fired on the first click.
    While I can understand why this is physically happening, our application users see this as a bug and want it fixed. Has anyone found a solution to this or reported it as a bug to Oracle?
    I tried searching for a solution and couldn't find anything useful. Bug I do seem to remember something I thought was in the adf-faces-config about passing click or first click, but now I cannot find it.
    Thoughts or ideas?

    Hi jdrogers,
    I feel your pain about the focus "jumping" back to the ppr-event object.
    I might have a solution for you to try.
    I did the following (after a lot af javscript debugging the alert way).
    Here is what i did:
    unziped Core.js from the file
    adf-faces-impl.jar
    put it in the following directory in my project:
    \public_html\META-INF\adf\jsLibs
    changed line
    2075 to
    _pprEventElement=null;//window.document.activeElement;
    Notice the difference in javacript code for "gecko" an IE.
    It now works for me.
    Could you (and everybody with the same problem) try this and tell me of any side-effect you might notice.
    To Oracle: is this a way of fixing this problem??? Does it cause any other problems??
    regards
    Johnny

  • Spontaneous scrolling and mouse clicks

    Not sure if this is a hardware problem or an OS or software problem, (or even one problem) but here goes. So far these problems have occurred in Word, Xcel and AOL as well as Finder.
    1. When working on a Word or Excel doc., spontaneously my window scrolls to the right so the left margin is obscured. I scroll manually back, but it does immediately back to the left. Sometimes a restart alleviates the problem temporarily. Sometimes I can work fine the entire session with no occurrence of the problem.
    2. In Excel, I can be working along fine, when suddenly spontaneous paragraph returns appear in my spreadsheet.
    3. In AOL, in the mailbox and AOL-address book windows, I can't stay scrolled vertically to where I want to be. The window bounces back to the top or bottom of the list. My mailbox is often pretty full and deleting old mail helps the problem. But my address book isn't that large and I should be able to scroll up and down.
    Also sometimes AOL will open messages from the mailbox without my clicking on them, and sometimes sends messages before I'm ready.
    Today, while I was having this problem I force-quit AOL. Without waiting for me to press enter or click the mouse, Finder force quit every application that was open.
    I've rebooted, repaired permissions and used TechTool Deluxe, and everything reports OK. But the problems persist.
    Powermac G5 dual intel   Mac OS X (10.4.8)   Apple optical USB Mouse

    Take a look at java.awt.event.MouseAdapter, which implements interfaces MouseListener, MouseMotionListener, MouseWheelListener and EventListener.
    For sample codes on how to use these classes, read through the posts on the Swing forum and you'll find plenty.
    If you have a more specific question, feel free to post back.
    db

  • HT201364 after converting to mavericks I cannot download any updates through app store and mouse click on download buttons does not respond, please assist

    Aftr converting to Mavericks could not able to update/download applications through spp store and have to force quit app store as the mouse does not click the X button

    Do you get any error messages?
    Try resetting the App Store.
    Reset       Learned from Old Toad
    Try deleting the com.apple.appstore.plist.
    Quit the application.
    Go to Finder and select your user/home folder. With that Finder window as the front window, either select Finder/View/Show View options or go command - J.  When the View options opens, check ’Show Library Folder’. That should make your user library folder visible in your user/home folder.  Select Preferences/com.apple.appstore.plist. Move the .plist to your desktop.
    Open the application and test. If it works okay, delete the plist from the desktop.
    If the application is the same, return the .plist to where you got it from, overwriting the newer one.
    Thanks to leonie for some information contained in this.
    You might need to redo the View settings after an update.
    App Store support. There is troubleshooting and a contact link.
    Support

  • Trackpad and Mouse click problem!! PLEASE HELP!

    I have been having this weird problem which is having to click several times on something of it to work. Mostly I have the problem with Safari and sibelius 6.0 which I work with.It doesn't click and its frustrating.I bet its not the trackpad as I happen to have a magic mouse and it's the same with that too.I have to click several times on for example "Close" the tab button for it to work.
    PLEASE HELP!

    Kirstiee, login to another User account and test it in there.
    sahba99, you would need to drag the whole preference folder to the Desktop and reboot. If it works, you know it's a preference file in that folder. Keep dragging a bunch back at a time and reboot (or log out and back in) until you narrow it down to the corrupt file. It's kind of like troubleshooting an extension conflict back in the pre-OS X days.
    Dave M.
    MacOSG v.2.0 coming April 1, 2010! No fooling! Check it out!
     MacOSG: An Apple User Group  iTunes: MacOSG Podcast  Follow us on Twitter: MacOSG

  • Wesnoth and mouse clicking problem

    As it says, my mouse suddenly stopped answering when I click.  Mouse works fine on any other program.

    spektre wrote:I have the exact same bug, but it worked fine before I did an update earlier today.
    I use the touchpad on my eee, no wired nor wireless mouse, don't think that has anything to do with it.
    Ah me too actually I did an upgrade and looking at pacman log I upgraded those packages:
    [2009-10-31 13:26] upgraded bash (4.0.033-1 -> 4.0.035-1)
    [2009-10-31 13:26] upgraded enca (1.11-1 -> 1.12-1)
    [2009-10-31 13:26] upgraded xulrunner (1.9.1.3-2 -> 1.9.1.4-1)
    [2009-10-31 13:26] upgraded firefox (3.5.3-1 -> 3.5.4-1)
    [2009-10-31 13:26] upgraded gd (2.0.35-2 -> 2.0.36RC1-1)
    [2009-10-31 13:26] upgraded kernel-headers (2.6.31.4-1 -> 2.6.31.4-2)
    [2009-10-31 13:26] upgraded lib32-glibc (2.10.1-4 -> 2.10.1-5)
    [2009-10-31 13:26] upgraded openssh (5.3p1-1 -> 5.3p1-2)
    [2009-10-31 13:26] Updating font cache... done.
    [2009-10-31 13:26] installed ttf-freefont (20090104-2)
    [2009-10-31 13:26] upgraded vlc (1.0.2-3 -> 1.0.2-5)
    Last edited by marxav (2009-11-02 22:37:20)

  • MBP Retina- trackpad and mouse click unresponsive

    Just got a brand new MBP retina, 15" 2.6Ghz Quad, 16GB Ram, 500 SSD.
    Been working with it for two days absolutely no issues, working fantastically with both trackpad and a wireless magic mouse.
    Used it this morning for several house, took it to work, turned it on and the mouse is working ie the cursor moved over the screen but i am totally unable to click anything! Forced it to restart (holding down power key as that was all that worked), hasn't cured the problem.
    The trackpad physically clicks so doesnt appear to be stuck, i tried plugging in a wired USB mouse, again can control the cursor but unable to click.
    Running 10.8.2, no new software was installed this morning when it worked fine, so cannot figure out what is wrong with it?
    Any suggestions?????

    Finally got it fixed. Make sure you guys call Apple Support. The first tier tech support is not able to help you because they have not been trained for that You will have to speak to a senior advisor. There will be a lot of deleting of caches involved while in safe mode. After did all that my trackpad and keyboard is working again. Hope you'll get yours working too!

  • JSlider and mouse click not working

    I am using a JSlider class so the user can choose a population size. I'm showing the slider with a scale from 0-100.
    When I move the slider button with my mouse the value changes. However, when I click anywhere else on the slider, nothing happens. It should be moving to the next minor tick. Here is my code snippet:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    (here's the construction of the slider)
    private JSlider m_popSizeSlider = new JSlider(0,100,20);
    m_popSizeSlider.addChangeListener(new SizeSliderHandler());
    // now handle the size slider
    m_popSizeSlider.setPaintTicks(true);
    m_popSizeSlider.setPaintLabels(true);
    m_popSizeSlider.setSnapToTicks(true);
    m_popSizeSlider.setMajorTickSpacing(20);
    m_popSizeSlider.setMinorTickSpacing(5);
    comboPanel.add(new Label("Size of Population: "));
    comboPanel.add(m_popSizeSlider);
    (here's the change listener code - defined as an inner class)
    class SizeSliderHandler implements ChangeListener
    * <p> This method is called when the user clicks on the size slider
    public void stateChanged(ChangeEvent e)
    JSlider s = (JSlider) e.getSource();
    m_popSize = (int) s.getValue();
    //System.out.println(m_popSize);
    so what am I doing wrong?
    thanks
    barry

    This page has lots of examples:
    http://www.esus.com/docs/GetIndexPage.jsp?uid=301

  • Mouse motion and mouse clicks

    I want to make a class that can detect these. How do I do this? I was thinking of using implementation of a Listener class but I'm not sure which and I'm not sure how.

    Take a look at java.awt.event.MouseAdapter, which implements interfaces MouseListener, MouseMotionListener, MouseWheelListener and EventListener.
    For sample codes on how to use these classes, read through the posts on the Swing forum and you'll find plenty.
    If you have a more specific question, feel free to post back.
    db

  • Mouse clicks occasionally stop working

    I am currently deploying a Java Swing application, and sometimes the end-user encounters an unusual problem whereby they open the application and mouse clicks have no effect. The mouse movement is still tracked fine, as buttons and menus get highlighted as expected when the mouse passes over them. I searched for information about this problem, and learned that a work-around is to click the middle mouse button. This does indeed restore the mouse click behaviour and all continues to work fine after that.
    So then I thought I might simulate a middle-button mouse click during my application start-up, in the hope of remedying the problem before any end-user actually sees it. The result is that instead of remedying the problem, I actually cause it to happen every time! The application gets into a state whereby mouse clicks are ignored, and clicking the middle-mouse button restores the mouse click behaviour.
    Has anyone else experienced this problem, and know of a way to prevent end-users from experiencing this problem? Here's some example code that demonstrates the behaviour:
    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class Main
        public static void main(String[] args)
            JFrame frame = new JFrame();
            frame.getContentPane().add(new JButton("Click Me"));
            frame.pack();
            frame.setLocationRelativeTo(null);
            try
                // Simulate a middle-button mouse click
                Robot robot = new Robot();
                robot.mousePress(InputEvent.BUTTON2_MASK);
            catch (Exception e)
                e.printStackTrace();
            frame.setVisible(true);
    }Note I'm using Java 1.6.0_07. Any help with this would be much appreciated,
    Paul.

    import java.awt.Robot;
    import java.awt.event.InputEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class Main
        public static void main(String[] args)
            JFrame frame = new JFrame();
            frame.getContentPane().add(new JButton("Click Me"));
            frame.pack();
            frame.setLocationRelativeTo(null);
            try
                // Simulate a middle-button mouse click
                Robot robot = new Robot();
                robot.mousePress(InputEvent.BUTTON2_MASK);
                // Simulate a middle-button mouse click again
                robot.mousePress(InputEvent.BUTTON2_MASK);
            catch (Exception e)
                e.printStackTrace();
            frame.setVisible(true);
    }?

Maybe you are looking for

  • Text auto-correct grabbing words from gmail / etc.

    I'm not sure if this is a Gingerbread issue, but this is a problem that I was introduced to when I got my Xperia PLAY.  The on-screen QWERTY keyboard lends itself to frequent typos.  Since I started using the Xperia, the auto-correct dictionary has b

  • Can't get MP4 Video to import

    These are the specs on a video file on my computer recorded off of a JVC GY-HM 100U. I can't get it to import into FCPX, and it wont' import into Compressor. What is apple's official stance on what to do with these files? What is the easiest way to g

  • HT4314 How do I get my games centre to stay logged in on my iPhone and iPad?

    I bought an iPhone 5 today and I tried logging into my games centre. It said it couldn't connect. So I logged out of my game centre on my iPad and it allowed me to connect to my iPhone, now it won't let me connect to my iPad! Please help, my sister i

  • Unable to type the maximum limit in scientific notation in a plot

    Hi, I am trying to plot some data that I measured in scientific notation (2E-19, etc) and I have tried everything to manually set the maximum/minimum limits of my plot in either axis without success. I have typed 2E-19 and even the number will all th

  • Create a playlist via Windows Me

    Hi there,?I have a ZEN V PLUS and I lost my program disc when i first bought it. So I've been loading my music onto my ZEN via Windows Media Player. I?need to have about 300 songs played in a specific order; so I need an alternate way to create load