Thursday, January 19, 2017

#1 2013-09-28 11:30:45 am

johndavidlewis
Member
Registered: 2012-12-05
Posts: 8

delay on pop up button

i have a virtual numbers pad, it seems when using keystrokes or key code values from the popup buttons, there is a small delay until the button is ready to be pressed again, which slows down input. Any Ideas ?
thanks in advance

Offline

 

#2 2013-09-30 03:52:36 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2550

Re: delay on pop up button

johndavidlewis wrote:

i have a virtual numbers pad, it seems when using keystrokes or key code values from the popup buttons, there is a small delay until the button is ready to be pressed again, which slows down input. Any Ideas ?
thanks in advance

Hello John,

AppleScript is single threaded which makes AppleScript-Studio also single threaded. During executing the code behind the button, it remains in a "pressed" state. When the process is finished the button is available again. If the button need to run code synchronously this isn't an issue (just change button behavior) but when the code needs to be executed asynchronously you should dispatch the code to another process using osascript (AppleScript-Studio application are 100% scriptable application internal as external).

Online

 

#3 2013-09-30 11:49:15 am

fondomatic
Member
Registered: 2013-08-27
Posts: 12

Re: delay on pop up button

DJ Bazzie Wazzie wrote:

AppleScript is single threaded which makes AppleScript-Studio also single threaded.

Not too sure about this. I use the following code in my AppleScript Studios-based project:

Applescript:

set uses threaded animation of progress indicator "progress" to true

Offline

 

#4 2013-09-30 05:42:03 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2550

Re: delay on pop up button

fondomatic wrote:

DJ Bazzie Wazzie wrote:

AppleScript is single threaded which makes AppleScript-Studio also single threaded.

Not too sure about this. I use the following code in my AppleScript Studios-based project:

Applescript:

set uses threaded animation of progress indicator "progress" to true

smile that has nothing to do with threading.

AppleScript is using Apple Events, which are similar to keyboard and mouse events. Keyboard and mouse events are triggered by external hardware while Apple Events are fired by software. Unlike mouse and keyboard events, the event listener for Apple Events needs to run on the main thread of the application/process. Because Apple Events can only be handled on the main thread it's called single threaded. When someone tries to execute AppleScript on another thread it's forced back to the main thread again, at least the event listener.

So back to the button. When an on-click-event is fired, the code is executed and puts the Apple Event listener in a busy state and makes your application's interface freeze for a short while (depending on size of the code behind it). During the firing of an event you can't fire another event and the up coming events are queued or ignored, depending on the type of events.

Example: Open in script editor two documents and do a sleep using a do shell script in one document, now every do shell script command is on hold in the other document because it waits for the event listener to be ready (after the sleep is complete). The exact same thing happens when pressing a button in Apple-Studio.

Reason: The reason for this behavior is the way Apple Events are handled. Apple Events are send to the Apple Event manager, which is responsible to send the event to the right process for interprocess communication. Like many messaging systems, once a message has been send the software waits for an reply. This applies for the event listener in the system as inside the application (process). During the time of sending and receiving an event the application's interface seems to freeze. The code that is firing the event needs to wait for a response because sometimes the return value is important like the "should" handlers in AppleScript-Studio.

Online

 

#5 2013-10-01 01:55:20 pm

johndavidlewis
Member
Registered: 2012-12-05
Posts: 8

Re: delay on pop up button

thanks guys for your reply's

hello dj

"If the button need to run code synchronously this isn't an issue (just change button behavior)"

so  I thought about what you said, so i  placed the script in a mouse up event, it definitely runs quicker, also I changed the mode of the button to momentary change. then i changed the double click settings in system preferences to fast.  now five repeated clicks of of the same button, will put four characters in my text field.

on mouse up theObject event theEvent
        tell application "System Events"
        tell process "keyPad"
            keystroke "1"
        end tell
    end tell
end mouse up

i am definitely more happy with the result but its still not a quick as keyboard viewers input

now i will look up a little about osascript, would this be a better approach ? or is it not possible with applescript to match the speed of keyboard viewer (i assume its written in objc) 

thanks

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.084 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)