Need some help with this script

Get help with using AutoHotkey and its commands and hotkeys
dilligence
Posts: 22
Joined: 25 Aug 2017, 14:31

Need some help with this script

25 Aug 2017, 15:06

I am a speech recognition user and I'm working on a (faster) dictation box for Dragon NaturallySpeaking. It's built in one works tediously slow. It is meant for speech unfriendly applications. So you first dictate into the box and then it's being transferred to the active application (that doesn't accept normal Dragon dictation).

The box is working, however the dictated text that is being sent via the edit field sort of lands letter by letter, and not as a whole (like when you normally copy and paste a selection of text).
This has some parallels with Dragon's SendKeys versus SendSystemKeys. That last one also sends letter by letter.

Am I using the correct function for this, or are there better alternatives?

Any help would be appreciated.

Rob

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Font, s10 Bold c0x00496C
Gui Add, Edit, ym vTransfer x26 y58 w659 h408
Gui Font
Gui Font, s12 Bold c0x0077B0, Ms Shell Dlg
Gui Add, Text, x26 y12 w493 h32 +0x200, Simple Dictation Box for Dragon NaturallySpeaking
Gui Font
Gui Font, s9 Bold c0x0080C0
Gui Add, Text, x27 y478 w459 h23 +0x200, Dictate your text in the field above and then simply Close This Box
Gui Font
Gui Font, s9 Bold c0x0080C0
Gui Add, Text, x26 y497 w485 h23 +0x200, You can use the standard Dragon "Close" command. To cancel say "press escape"
Gui Font
Gui Font, s9 Bold c0x0080C0
Gui Add, Text, x27 y515 w460 h23 +0x200, Your text will be pasted into the Active Application
Gui Font
Gui Font, s9 Bold c0x0080C0
Gui Add, Text, x612 y15 w95 h26 +0x200, by Dilligence
Gui Font

Gui Show, w713 h556, simple dictation box
Return

GuiEscape:
GuiClose:
SetKeyDelay 30,50
Send, {ALT DOWN}{TAB}{ALT UP} 

gui, submit  
Send %Transfer%
ExitApp 

ESC::ExitApp
BoBo
Posts: 3757
Joined: 13 May 2014, 17:15

Re: Need some help with this script

26 Aug 2017, 13:30

What about to use ControlSetText instead ?
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Need some help with this script

26 Aug 2017, 18:37

This is caused by this line SetKeyDelay 30,50 either change it to a small delay or use SendInput instead of send or change the SendMode.
dilligence
Posts: 22
Joined: 25 Aug 2017, 14:31

Re: Need some help with this script

27 Aug 2017, 16:56

Thank you BoBo and obeeb for your input. I tried both: ControlSetText doesn't seem to work here and adjusting SetKeyDelay (or even leave it out completely) does speed things up a little.
One of the KnowBrainer (speech) forum members came up with a working solution. It pastes all text at once.

However now the script works by simply closing it (which is not very elegant). What I want is to associate this action with the Transfer button I have created in the left down corner.

How do I accomplish that?

I tried the label function and the default button function but I cannot get it to work......

Here's the script so far:

Code: Select all

; Created with AutoGui
#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui -Caption  ; Or use Gui, GuiName:-Caption if it isn't the default window.
Gui Font, s10 Bold 
Gui Add, Edit, ym vTransfer x26 y58 w659 h380
Gui Font
Gui Font, s12 Bold, Ms Shell Dlg
Gui Add, Text, x26 y12 w493 h32 +0x200, Simple Dictation Box for Dragon NaturallySpeaking
Gui Font
Gui Font, s9 Bold 
Gui Add, Text, x540 y15 w160 h26 +0x200, by Dilligence and PG LTU
Gui Font
Gui Font, s13 Bold 
Gui Add, Button, x25 y455 w160 h69, &Transfer
Gui Font

Gui Show, w713 h556, simple dictation box
Return

GuiEscape:
GuiClose:
SetKeyDelay 30,50
Send, {ALT DOWN}{TAB}{ALT UP} 

gui, submit 
curClip := ClipboardAll 
Clipboard = %Transfer% 
Sleep, 150 
Send ^v 
Clipboard = %curClip% 
ExitApp 

ESC::ExitApp
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Need some help with this script

27 Aug 2017, 20:18

You need to add a label that starts with Button and ends with the name of your button:

Code: Select all

ButtonTransfer:
GuiEscape:
GuiClose:
dilligence
Posts: 22
Joined: 25 Aug 2017, 14:31

Re: Need some help with this script

28 Aug 2017, 10:23

Thank you obeeb!

That works.
One last question: let's say I wanted to add some other buttons (for text editing for instance). Would that involve exactly the same procedure?
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Need some help with this script

28 Aug 2017, 12:49

Similar yes, let's say you added a button named Something you will need to add a new label:

Code: Select all

ButtonSomething:
; do something
return
dilligence
Posts: 22
Joined: 25 Aug 2017, 14:31

Re: Need some help with this script

28 Aug 2017, 15:06

OK the Transfer button is working. I also added a Transfer to Wordpad button which is also working. Finally I added a Cancel button which closes the GUI but the script itself doesn't close (it stays in the system tray). And not only that, it also closes the active application.....
I have no idea why this is.

Any ideas on how to close the script properly with the Cancel button (and not closing the application I am using it in) ?

Here is the code so far:

Code: Select all

; Created with AutoGui
#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui -Caption  ; Or use Gui, GuiName:-Caption if it isn't the default window.
Gui Font, s10 Bold 
Gui Add, Edit, ym vTransfer x26 y58 w659 h380
Gui Font
Gui Font, s12 Bold, Ms Shell Dlg
Gui Add, Text, x26 y12 w493 h32 +0x200, Simple Dictation Box for Dragon NaturallySpeaking
Gui Font
Gui Font, s9 Bold 
Gui Add, Text, x540 y15 w160 h26 +0x200, by Dilligence and PG LTU
Gui Font
Gui Font, s13 Bold 
Gui Add, Button, x26 y455 w160 h69, &Transfer
Gui Font
Gui Font, s13 Bold 
Gui Add, Button, x526 y455 w160 h50, Cancel

Gui Font
Gui Font, s7 Bold   
Gui Add, Button, x200 y455 w120 h40, Transfer to Wordpad

Gui Font

Gui Show, w713 h556, simple dictation box
Return

ButtonCancel:
gui, submit
Send !{F4}
return


;no space here if your button label name has spaces!
ButtonTransfertoWordpad:
gui, submit 
curClip := ClipboardAll 
Clipboard = %Transfer% 
Sleep, 150 
Run wordpad.exe
Sleep, 500
Clipboard = %curClip% 


ButtonTransfer:
gui, submit 
curClip := ClipboardAll 
Clipboard = %Transfer% 
Sleep, 500 
Send ^v 
Clipboard = %curClip% 
GuiEscape:
GuiClose:

ExitApp
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: Need some help with this script

28 Aug 2017, 15:25

Just do:

Code: Select all

ButtonCancel:
exitapp
return
dilligence
Posts: 22
Joined: 25 Aug 2017, 14:31

Re: Need some help with this script

28 Aug 2017, 15:40

wow, that simple and it works!
Thank you!

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], hasantr, RubbeH, songdg, Xtra and 48 guests