AppleScript: Keys Pressed test?

The appleScript below runs fine in OSX 10.4.11, but in OSX 10.5.8, the "Keys Pressed" bit of the "IF" statment is corrupted. How do I get this to work in 10.5.8?
Thanks
Note: Apologies that Apple 21st century forum technologies do not preserve formatting, indentation etc...
on run
tell application "Finder"
activate
make new Finder window
if (keys pressed) contains "Shift" then
set bounds of Finder window 1 to {15, 34, 1520, 585}
else
set bounds of Finder window 1 to {15, 616, 1520, 1210}
end if
set current view of Finder window 1 to column view
end tell
end run
on reopen
run
end reopen

taylor.henderson wrote:
William Donelson wrote:
Thank you, all. Very interesting and helpful.
Why do you think AppleScript cannot detect ShiftDowns? Seems strange.
It has to do with what applescript is designed for, mainly specific task you are hoping to automate and not stay open monitoring etc. As for asking why Applescript can't detect ShiftDown you need to define your terms a little better. System Events can't detect ShiftDown, but can trigger keystrokes from within applescript, and there are extensions that can detect shiftdown which could be called from an applescript.
In this case, when launched/clicked, the script opens a Finder windows of a certain size at the bottom of the screen. If the ShiftKey is down when launched/clicked, it opens a smaller window at the top of the screen.
Is there another way to do this without having two AppleScript apps in the dock?
thanks

Similar Messages

  • AppleScript to press Escape key (3x) for Excel

    Hi all,
    I'm trying to automatically convert Excel files to PDFs using Automator. Although, every time the Excel file is opened, I get a message about links to other workbooks. I really don't care about these links and just want to convert the file to a PDF. I just can't get Automator to press the "Ignore links" button on the Excel message.
    Now I've found out that pressing the escape key on my keyboard activates the following buttons on the Excel message about the links:
    - "Update links" (then there's a Finder window popping up)
    - "Cancel" (the search for other workbooks) (another Finder window pops up)
    - "Cancel" again
    Then Excel opens up the file I need to convert, so I can actually convert it using Automator and do whatever I want with it.
    I have absolutely no experience using AppleScript.Is there a way to make a AppleScript that presses the escape key three times, so that Excel just opens my file?
    Thanks in advance

    Pressing the Escape key is trivial:
    tell application "System Events"
              repeat three times
      key code 53
              end repeat
    end tell
    Invoking this script at the right time is what's harder (plus, you might need a small delay between each keystroke to allow for the OS to handle the keystroke and display the next dialog, otherwise the second and third keystrokes might get lost.

  • How to pass the key pressed in javascript

    I'm asking this question here as I could not find the needed help elsewhere .
    I don't know how to pass the key pressed in the function on OnKeyPress event .
    I'm trying the following :
    <input type="text" name="a" onKeyPress="check();">
    I want to pass the key presses in the check function .
    How to collect the key pressed in the function check ?
    Thanks.

    As I said above, that won't work in Mozilla.
    In fact IMO Netscape/Mozilla javascript event handling has been behind IE since version 4.
    Be that as it may: here is a workaround (for Mozilla): It seems you have to assign the onkeypress event for it rather than declaring it as part of the textfield.
    Of the two textfields on this form, both work in IE, and only the first one will work properly in Mozilla. I left it in just to demonstrate the difference.
    And a couple of links for ya
    javascript forum: http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=3
    Keypress events: http://www.din.or.jp/~hagi3/JavaScript/JSTips/Mozilla/Samples/KeyEvent.htm
    <html>
    <head>
    <script language="javascript" >
    <!--
    function check(evnt){
      alert("A key was pressed!");
      // IE handling
      if (window.event){
        evnt = window.event;
        alert(evnt.keyCode);
      // netscape/mozilla handling 
      else{
        alert(evnt.which);
    //-->
    </script>
    </head>
    <body >
    <form name="myform" method="post">
    Test <input type="text" name="myTest"><BR>
    Test <input type="text" name="myTest2" onKeyPress="check();"><BR>
    <script> document.myform.myTest.onkeypress = check; </script>
    </form>
    </body>
    </html>

  • Key pressed event

    I need message to be displayed when certain key pressed. Why it's not working?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestKey extends JPanel implements KeyListener {
         public TestKey(){
              addKeyListener(this);
         public static void main(String arg[]){
               JFrame frame = new JFrame();
                  frame.setTitle("Test my keybord, man!");
                  frame.setSize(300, 200);
                  frame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  Container contentPane = frame.getContentPane();
                  contentPane.add(new TestKey());
                  frame.setVisible(true);
         public void keyPressed(KeyEvent ke){
              System.out.println("key pressed");
         public void keyTyped(KeyEvent ke){
              System.out.println("key typed");
         public void keyReleased(KeyEvent ke){
              System.out.println("key released");
    }

      public TestKey(){
        setFocusable(true);//<----------
        addKeyListener(this);
      }

  • Flash 9 Key press Problem

    Using Flash 9, when running an application from the IDE, key
    presses of K which are supposed to do something in my app are being
    captured by the IDE and doing something there instead.
    Didn't happen in flash 8, is there a way to disable / fix
    this.

    Plucka,
    > Using Flash 9, when running an application from the IDE,
    > key presses of K which are supposed to do something in
    > my app are being captured by the IDE and doing something
    > there instead.
    While in the SWF window you're testing in the IDE, go to
    Control >
    Disable Keyboard Shortcuts. Let me know if that does it for
    you. :)
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • Multiple Key Pressing

    When I hold Tab + w space doesn't work click (I have my controls set as this for a game).
    Is there anyway to make it so i can hold those two keys and have spacebar work?
    Im on a MacBook Pro Retina 13 inch with latest version of yosemite
    Thanks for the help

    Here is an example of both multiple key press and repeat delay ignore. It is a terrible example of animation. Do not us this animation loop in a game. It will flicker far too much.import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends JFrame implements Runnable {
      boolean upPressed=false, downPressed=false, leftPressed=false, rightPressed=false;
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent ke) {
         switch (ke.getKeyCode()) {
           case KeyEvent.VK_UP: upPressed = true; break;
           case KeyEvent.VK_DOWN: downPressed = true; break;
           case KeyEvent.VK_LEFT: leftPressed = true; break;
           case KeyEvent.VK_RIGHT: rightPressed = true; break;
          public void keyReleased(KeyEvent ke) {
         switch (ke.getKeyCode()) {
           case KeyEvent.VK_UP: upPressed = false; break;
           case KeyEvent.VK_DOWN: downPressed = false; break;
           case KeyEvent.VK_LEFT: leftPressed = false; break;
           case KeyEvent.VK_RIGHT: rightPressed = false; break;
        setSize(250,250);
        setVisible(true);
        Thread timer = new Thread(this);
        timer.start();
      public static void main(String[] args) {
        new Test();
      public void run() {
        while (true) {
          repaint();
          try { Thread.sleep(30);} catch (Exception e) {}
      public void paint(Graphics g) {
        g.setColor(Color.white);
        g.fillRect(0,0,getWidth(), getHeight());
        g.setColor(Color.black);
        g.drawString("Up",40,40);
        if (upPressed) g.drawString("Pressed",100,40);
        g.drawString("Down",40,60);
        if (downPressed) g.drawString("Pressed",100,60);
        g.drawString("Left",40,80);
        if (leftPressed) g.drawString("Pressed",100,80);
        g.drawString("Right",40,100);
        if (rightPressed) g.drawString("Pressed",100,100);
    }

  • What are the key presses like on the Enhanced Performance keyboard?

    Hi guys,
    I've been thinking about buying this keyboard:
    http://shop.lenovo.com/SEUILibrary/controller/e/gbweb/LenovoPortal/en_GB/catalog.workflow:item.detai...
    I was wondering how the key presses feel?   I'm quite particular about it.   I like the press to have a definite 'soft click' (like a cross between a microswitch and a diaphragm).    A lot of keys these days are like pressing a spring with no tactile response as to when a key press has actually been registered if that makes any sense.
    Can anyone with this keyboard describe how the keys are to press?   I can't find and videos or any real life examples to test.
    Thanks,
    Leo

    if you are looking for tactility in a keyboard, than this keyboard is not the best. Maybe you should get a Filco keyboard instead.
    Microsoft and Dell's keyboard (the one with oversized spacebar) are both slightly better than these Lenovo keyboard. Alternatively get the Space Saver II keyboard. 
    Regards,
    Jin Li
    May this year, be the year of 'DO'!
    I am a volunteer, and not a paid staff of Lenovo or Microsoft

  • Simultaneous ASDW key press undetected

    Hi guys, I'm currently developing a game that uses ASDW buttons for its movement system
    During one of my testing session, i realized that if i press 2 buttons simultaneously, (ex: A and S), both events would be dispatched one after the other (just like what i assume they would do)
    But if i press 3 buttons simultaneously, (ex: A, S and D), the last keypress (D) will go undetected
    Only after i release one of the keys (either A or S) will the last keypress be detected
    From what i read here ==> http://blog.nobien.net/2008/05/12/more-than-two-simultaneous-key-presses-and-keyboardevent key_down-woes/
    It is said that the problem might had been caused by a hardware issue
    From what i read at wikipedia http://en.wikipedia.org/wiki/Keyboard_%28computing%29
    [quote]
    Some low-quality keyboards suffer problems with rollover (that is, when multiple keys are pressed in  quick succession); some types of keyboard circuitry will register a  maximum number of keys at one time. This is undesirable for games (designed for multiple keypresses, e.g. casting a spell while holding  down keys to run) and undesirable for extremely fast typing (hitting new  keys before the fingers can release previous keys). A common side  effect of this shortcoming is called "phantom key blocking": on some  keyboards, pressing three keys simultaneously sometimes resulted in a  4th keypress being registered.
    Modern keyboards prevent this from happening by blocking the 3rd key  in certain key combinations, but while this prevents phantom input, it  also means that when two keys are depressed simultaneously, many of the  other keys on the keyboard will not respond until one of the two  depressed keys is lifted. With better keyboards designs, this seldom  happens in office programs, but it remains a problem in games even on  expensive keyboards, due to wildly different and/or configurable  key/command layouts in different games.
    [/quote]
    Question
    - What causes this problem is it a hardware issue or a language/flash player problem?
    Because i might be wrong, but i think i've played several non-flash games before that possess the ability to address multiple keypress at the same time
    - Can this problem be fixed?
    Code
    package
            import flash.display.Sprite;
            import flash.events.KeyboardEvent;
            public class Keyboard extends Sprite
                     public function Keyboard()
                            this.stage.addEventListener("keyDown", showKey);
                    public function showKey(event:KeyboardEvent)
                            trace(event.keyCode);
    Any help regarding the matter is greatly appreciated, thank you in advance~

    Quote
    do you think an update of the bios will do the trick?
    No, no, no, it won't, so please don't try it!
    Also, if you read the comments in the link you posted, your answer is there:
    Quote
    By Tony Fendall on May 12, 2008 | Reply
    The problem comes from the way in which the signal for the pressed keys moves from your keyboard to your computer. The signal is only 8-bit, and there are limits to how the signal can be changed to represent more than one key being pressed in combination.
    Long story short, the guys who designed the origional keyboards made a descision to support all two key combinations, and then selected as many three key combinations as they could support with the hardware. This meant that some combinations had to be left out, and they had to make a descision about which ones were more important.
    It just happens to be that they chose not to support three key combinations which involve the up arrow key. I do not think there is any solution to this problem…
    If you're playing games, why not just remap the keys in the game's settings?

  • KEY PRESS ISSUES

    I own a Pre Plus on Verizon. I have read the numerous posts describing issues with keyboard key press difficulties. What I haven't seen, is any resolution to the problem. Personally, The keyboard size is OK. The unreliable key press issues are driving me nuts. The worst key on my Pre+ is the "e" key and some others, mostly on the top row of keys. I first press, nothing, press again, maybe nothing or multiple entries of "e", The "y" is second worst. Same issues. Is ANYBODY doing anything to resolve this problem?
    Post relates to: Pre Plus p101vzw (Verizon)
    This question was solved.
    View Solution.

    The last software update 1.4.11 addressed this issue on the Verizon Palm Pre Plus. If you are on earlier software version you need to update your device to the latest SW version. If you are on the latest SW version you may have a hardware problem with the device. You should go to Device Info from your launcher, tap the drop-down menu, choose Tests, then Interactive Tests, then test your keypad for problems. If this test fails then you should get a replacement device from Verizon.

  • Getting the value of a key pressed

    This is a pretty simple question, but one which I can't seem to find the answer to...
    How do you determine which key (or keys) have been pressed with the keyboard down event?
    My app generates lists of files that match certain criteria, and I'd like the user to be able to Quicklook the files, before deciding which ones to open...
    I have it working where the user has to click a button, but I'd like to intercept the spacebar, and activate QL that way.

    To clarify, you want something like this:
    "if key pressed is "option" then (do something)" ??
    For this, I've used two things on a PPC running 10.3 and 10.4.
    One is a scripting addition from Jon's Commands, a free download. The specific command is "keys pressed." Although I don't have an Intel machine, I was trying to look ahead and contacted the developer, Jon Pugh, who replied that it was unlikely this would be updated for Intel. (It might work on PPC 10.5, don't know. But it looks like you could try it on your non-Intel machines.)
    The other is an application called "Extra Suites." This is not free, but does have quite a few interesting commands, including "keys down." The original version, released some years ago, is not for Intel (don't know about 10.5). but the developer reports that he is trying for an Intel release early this year. You can download the PPC version via Versiontracker or MacUpdate, but the developer's website (http://www.kanzu.com/) was last updated in 2004. I contacted him by a link on that site, which is how I learned of the impending Intel update (and website update, he said). He seemed to be looking for people to test the Intel version, so you might try contacting him.
    I may be wrong, but I think the "keyboard down event" that you mention is used in the opposite sense (in a System Events tell block), e.g, 'keystroke "r" using command down' which has the script "press" r, if for some reason you want that.

  • Simultaneous key press on the keyboard GX600

    hello guys,
    i bought a MSI GX-600 thinking that it could accommodate my gaming needs however i found out that it cannot allow more than 2 simultaneous key presses on the keyboard. its supposed to be a gaming laptop right? i cannot play keyboard bashing games with this unless i use a gamepad or an external keyboard. have you experienced this on your laptop? 
    do you think an update of the bios will do the trick?
    try this link to test if your keyboard can handle more than 2 keypress at the same time:
    http://blog.nobien.net/2008/05/12/more-than-two-simultaneous-key-presses-and-keyboardeventkey_down-woes/
    btw, i like this forum. 

    Quote
    do you think an update of the bios will do the trick?
    No, no, no, it won't, so please don't try it!
    Also, if you read the comments in the link you posted, your answer is there:
    Quote
    By Tony Fendall on May 12, 2008 | Reply
    The problem comes from the way in which the signal for the pressed keys moves from your keyboard to your computer. The signal is only 8-bit, and there are limits to how the signal can be changed to represent more than one key being pressed in combination.
    Long story short, the guys who designed the origional keyboards made a descision to support all two key combinations, and then selected as many three key combinations as they could support with the hardware. This meant that some combinations had to be left out, and they had to make a descision about which ones were more important.
    It just happens to be that they chose not to support three key combinations which involve the up arrow key. I do not think there is any solution to this problem…
    If you're playing games, why not just remap the keys in the game's settings?

  • Virtual key press of an external usb device

    Dear champs,
    There is an USB device which has a keypad with 10 keys. During the testing of device, the keys has to be pressed and for every keypress there will be some actions involved.
    The idea was to automate the key press without any manual intervention. I hope some hardware will help in achieving the key press action. I mean some DAQ (example) hardware will simulate some signals that will be equivalent to the key press.
    Does my query makes sense. Please throw some lights.
    Thanks for ur patience.
    Mathan

    A few years ago, I had a similar issue, which I solved using C. When the key was pressed on the USB device, it sent a keyID number to user32.dll. The program I was communicating with read the keyID and did it's action. As the hardware and software were both bespoke, the software knew what do to with the keyID.
    To simulate the USB device I set up a program which would capture events sent to the keyboard function in user32.dll and record the key number. Then to simulate the device, I simply sent the integer number to user32.
    I would sugest seeing if you can do a similar thing and read the numerical value for the key being pressed.
    Alternately you could see if you are able to access the driver dll while the device is running, and have a look at what data is being passed around, then seeing if you are able to inject your own into it.
    Message Edited by yenknip on 07-31-2008 12:26 PM
    - Cheers, Ed

  • What to use for the events of 2 keys pressed simultaneously?

    Question:
    What to use for the events of 2 keys pressed simultaneously? As the key listener has limited functionality, in this case, I need something that can act to two events (see below)
    Goal
    1. A user presses right and up at the same time
    2. Program responds to this event changing BOTH the vertical and horizontal speeds of the player
    Problem
    I currently have a key listener to do this, using key pressed, however, it only acts to up OR right at one point in time. So the user can only increase his or her vertical speed; or horizontal speed at one point in time. Instead of increasing them both.
    Example
    Here is an example of the game: http://www.kongregate.com/games/MINDistortion/bubbles-2

    DarrylBurke wrote:
    I don't know whether there's a better way (or whether this will work as expected), but I would try setting a boolean flag on keyPressed and reset the flag on keyReleased, for each key of interest. To compute the x / y movements, I would check the state of all flags.
    dbI was thinking about your answer a few nights ago. And I was like, wait... it works! I thought, at first (as I replied before) that it wouldn't work, but I refract what I said. Its actually a very simple solution. And I apologize for questioning your solution previously. Thanks so much!
    P.S. I tested it out. Works like a charm.
    -Create booleans to handle each key
    -Set to true on press
    -Set to false on release
    -Check and update in separate thread accordingly

  • Missed Key Press

    I first noticed missed key press after installing and later removing Bootcamp.
    After several months of missing key presses, I uninstalled Internet Explore.
    The missed key presses were gone (unnoticed) for more than a week and then they started intermittently.
    After the Bootcamp removal and before the Internet Explore removal, I would notice the cursor flash about 10 times and stop. Then the next key press would miss.
    After Internet Explore removal, I have not seen the cursor stop, but I still get missed key presses. I tested it just now, counted 100 cursor flashes and the next key press missed. Repeated 100 count again and key press okay.
    Summary:
    Missed Key Press:
    iMac 17", OS 10.5.8
    After Bootcamp uninstall, missed key press after 7-10 cursor flashes always.
    After IE removal, missed key presses seemingly random.
    I seen old posts (2006 - 2009) about missed key press which were archived without answers.
    Any help would be appreciated.

    Capslock blinking twice and then repeating  is a diagnostic error message that means that the BIOS is corrupt.
    Try a hard reset as follows:
    1) Remove the battery and unplug the DC power adapter.
    2) Press and hold the power button for more than fifteen seconds.
    3) Plug in the DC power adapter (leave the battery out for now)
    4) Press the power button
    Please post your positive or negative results here in your thread.
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • Backlight key presses not detected, OPTIMUS, wiki didn't help

    I am using a Razer Blade 14" with linux-ck kernel (although I have tested in the main kernel and the issue remains).
    The keyboard brightness settings keys are not detected by X at all (using xev reports no keycodes when I press them).
    However, the driver is getting that information. And in the same type as other function keys (such as sound up/down - which are detected correctly).
    I know this because, while investigating the workings of the touchpad, I ran the razer-test script found in:
    http://fxchip.net/RazerBlade/
    (slightly modified because the device ID is 0x011D in the 14").
    It distinguishes normal key presses from Macro Keys. Function keys in this laptop are macro keys. When pressing volume down, I get the following report:
    Macro keys: Razer Extra Buttons:
      Extra key: FN
    04 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Macro keys: 02 ea 00 00
    Macro keys: 02 00 00 00
    Macro keys: Razer Extra Buttons:
    04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    When pressing brightness up/down, I get the following report:
    04 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Macro keys: 02 70 00 00
    Macro keys: 02 00 00 00
    Macro keys: 02 6f 00 00
    Macro keys: 02 00 00 00
    Macro keys: Razer Extra Buttons:
    04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    (note that the last part just signals that I let go of the FN key)
    My idea was to try to find the keycodes through xev and then map them manually. However, this was unsuccessful since xev reports no input when I press brightness up/down (while volume up/down works).
    This is where I'm lost - the keyboard drivers seems to just be ignoring them.
    Any help appreciated . Let me know what I can post if it's of any help!
    Cheers,
    Rodrigo
    EDIT:
    My laptop uses optimus hardware, and I'm using the integrated Intel Graphics card.
    I have tried all the methods in the wiki but none of them worked:
    https://wiki.archlinux.org/index.php/backlight#Overview
    https://wiki.archlinux.org/index.php/In … ter_resume.
    It's also worth noting that I do have control over the backlight with software - the FN+F8/F9 key bindings are the ones that are just completely ignored by the driver.
    Last edited by rgomes (2013-11-22 18:47:57)

    maxo wrote:
    Hey. If you aren't using the nvidia graphics card then this works on mine.
    Edit the /etc/X11/xorg.conf.d/20-intel.conf by adding
    Option "Backlight" "intel_backlight"
    Xorg normally automatically selects the backlight device. On mine it ued acpi_video0 instead of intel_backlight.
    Hope that helps!
    Thanks, but the challenge is, to get nvidia prop. drivers working.
    I think, I tracked the problem down to some backlight issue, probably a firmware issue with the laptop model.
    On ubunutu, ideapad backlight modules gets loaded, on arch, it uses the intel-bl. As it stands to reason, backlight settings are too dim when starting X.
    I am about to test nvidia-bl from AUR.

Maybe you are looking for

  • Tried everything - Still Lost. Open NAT but can't connect to certain people on Xbox Live.

    Title really says it all, really.  Odd thing is that this happened out of nowhere. In November/December of last year we were all playing fine. In January my NAT went from open to strict, so I opened it back up promptly. Out of the blue I can't seem t

  • File Share Cluster Transfer Issues - Windows 2012 R2 - Two Nodes

    Hi There, I am having some issues in creating a simple file share on a 2 node cluster. Each "File Server" is Windows 2012 R2 Standard. Each server has 4 Nic Ports, 2 are configured as a Control Team and the other 2 as a Media Team.  The media team is

  • How reduce pop up ads without completely blocking pop-ups

    All of a sudden ads pop up all over my browser. How can I stop this from happening. But I don't want to turn on block all plug-ins.

  • A tribute to Nokia Lumia

    I came to this forum after four years I bought a nokia smartphone.first one was nokia N8. I had it for two years and then I bought Nokia Lumia 920. I had it for two years and i came here  just to give a tribute to Nokia because I think It deserve it.

  • MPC sequencing Using Logic Plug ins

    Whats the best way to set up logic so I can sequence my music using the MPC 4000 sequencer therefore utilizing all Logic Virtual Instruments on midi channels in the MPC? Then when i'm done in the MPC I'll imort all the MIDI data to logic hence retain