How can I code Command key Command key, which is to click the Command Key twice in a pushbutton?

Hello,

I have an app that I created and the Keyboard shortcut to start dictation is Command key Command key, which is to click the Command Key twice.

How can I code that in a pushbutton?

Thanks.

Lennox

What do you mean by “code that in a pushbutton” ? If you want the pushbutton to replace double hit Command, that may be possible with MBS plugins.

Right now, where is the logic triggered by double Command hit ?

This is the TextEdit version of my app.

MGM Screenshot 2022-06-08 at 2_2022_06_08__14_39_39

I would like to code that in a pushbutton sine it is easier to click on a pushbutton rather than clicking twice on the Command key on the keyboard.

Thanks.

Lennox

I was thinking something like this Pseudocode…

If Keyboard.AsyncCommandKey then
If Ticks - StartClick < 15 then
If Keyboard.AsyncCommandKey then
Edit Menu(18) clicked
Start Dictation
end if
end if
end if

end if

Could that be coded in Xojo?

Thanks

Why not make the pushbutton directly invoke whatever routine you have that does the dictation. There is no need to involve the keyboard at all to start the dictation.

Thanks Tom,

But I do not know how to code for “Start Dictation”
Any suggestions?

Thanks.

Lennox

Looking back at your screenshot it occurs to me you are wanting to use Xojo to start dictation in TextEdit?

Maybe search the internet for a sendkeys application would be a better approach.

Edit: a Quick search and I found a link on how to use AppleScript for this.
https://apple.stackexchange.com/questions/314647/applescript-command-sendkeys

Hi Tom,

This AppleScript works as a standalone AppleScript…

tell application “System Events”
key code 55
key code 55
end tell

but when I use it in my app it does not work, I will continue to work on it and let you know.

Thanks again.

Lennox

Look at the “new” security behaviour of Mac OS, which started since Mac OS 10.14, where you don’t have the same rights in an app that invoke AppleScripts than in the Script Editor. You know, these irritating messages asking “ wants to control “Finder”. Do you want to allow that?”. If your app doesn’t have the required entitlements (or isn’t wrapped and notarised), using AppleScript in your app won’t even show these dialogs asking the user to allow and just deny the script’s AppleEvent from being delivered, silently.

Simply create a new method StartDictation containing the code presently in the menu handler, which is triggered either by the menu handler, or by the button.

Well, I don’t think you can use this shortcut in macOS via MenuItem class in Xojo.

To start dictation, you can use startDictation method in our NSApplicationMBS class in MBS Xojo Plugins.

Thanks Arnaud,

The issue is that when that AppleScript is fired it gets executed but the “Dictation Engine” is expecting somewhere to put the text, but the AppleScript has already been closed so the Dictation command cannot be executed.

What happens in my opinion is that the “Dictation Engine” has to be called from my app, and I do not know how to call that “Dictation Engine”.

Lennox