Jump to content

Recommended Posts

Posted

Hello everyone

I'm trying to send keys to a specific program on my computer (using "Send"), but all keys sent to it simply disappear (i.e. the program does not respond to those keys being sent). For example, Send ("{LEFT}") does nothing in that program, but if I press the LEFT arrow on my keyboard, the left-arrow action works perfectly.

Some Hotkeys also don't work with this program... I had to try a couple to find a hotkey that works (e.g. if NumpadAdd is the Hotkey, then pressing NumpadAdd while I'm using that program simply types a "+" in that program, while in any other program the Hotkey works fine). This isn't related to NumLock.

The program is LocStudio, but I doubt if many people here have it. It's an Excel look-alike with cells into which I must paste hundreds of little snippets of text.

Anything you can think of that might help AutoIt to overcome the resistance?

Thanks

Samuel

==

Posted (edited)

My first thoughts are post your code.

My code is a mess... but if you insist:

 

#include <Process.au3>
#Include <Array.au3>

#cs

TranzVoo is based on one of my "glosslookup" scripts. Those scripts helped translators look up terms in a glossary. The TranzVoo also looks up "terms" in what might be called a glossary, but the current script checks only for exact matching "terms".

#ce

Global $fileopenhtml, $glossaryfilecolumns, $glossaryfilelines, $glossaryfileopen, $glossaryfileopendialog, $glossaryfileread, $grabbedtext, $grabbedword, $grabbedwordarray, $htmloutput, $i, $j, $k, $l, $output, $found

MsgBox (0, "locstudio TranzVoo v2", "TranzVoo looks up strings in a mini-TM. This one is customised for Passolo. Read the instructions in the readme.txt file." & @CRLF & @CRLF & "Shortcuts:" & @CRLF & @CRLF & "Ctrl + Num-plus = find translation and paste it into the current cell" & @CRLF & "WinKey + Q = Exit the program (or right-click its icon)", 0)

HotKeySet("^{NUMPADSUB}", "seekandpaste")
; HotKeySet("{NUMPADSUB}", "seekandkeep")

HotKeySet("#q", "exitty")

$glossaryfileopendialog = FileOpenDialog ("Select mini-TM", @ScriptDir, "Text files (*.txt)|All files (*.*)") ; uncomment this to be asked for glossary at start of run

#cs
$glossaryfileopendialog = @ScriptDir & "\mini-TM.txt" ; comment this if you uncomment the above
#ce

$glossaryfileopen = FileOpen ($glossaryfileopendialog, 128) ; 128 means UTF8, 32 means UTF16LE
$glossaryfileread = FileRead ($glossaryfileopen)

$glossaryfilelines = StringSplit ($glossaryfileread, @CRLF, 3)

Global $glossaryfilefirstcolumn[UBound ($glossaryfilelines)]
Global $glossaryfilesecondcolumn[UBound ($glossaryfilelines)]

For $i = 0 to UBound ($glossaryfilelines) - 1
$glossaryfilecolumns = StringSplit ($glossaryfilelines[$i], @TAB, 3)
If UBound ($glossaryfilecolumns) = 2 Then ; i.e. if there is 2 columns in the line
$glossaryfilefirstcolumn[$i] = $glossaryfilecolumns[0]
$glossaryfilesecondcolumn[$i] = $glossaryfilecolumns[1]

$glossaryfilefirstcolumn[$i] = StringReplace ($glossaryfilefirstcolumn[$i], "[[CRLF]]", @CRLF)
$glossaryfilesecondcolumn[$i] = StringReplace ($glossaryfilesecondcolumn[$i], "[[CRLF]]", @CRLF)

EndIf
Next

; MsgBox (0, "", _ArrayToString($glossaryfilefirstcolumn, " | "), 0) ; If you want to check that the entire glossary was read
; MsgBox (0, "", _ArrayToString($glossaryfilesecondcolumn, " | "), 0) ; If you want to check that the entire glossary was read

While 1
Sleep ("100")
WEnd

Func exitty ()
Exit
EndFunc

Func seekandpaste ()

Send ("{ESCAPE}")
Sleep ("100")
Send ("{LEFT}")
Sleep ("100")
Send ("{F2}")
Sleep ("100")
Send ("^a")
Sleep ("100")
Send ("^c")
Sleep ("100")
Send ("{ESCAPE}")
Sleep ("100")
Send ("{RIGHT}")
Sleep ("200")
$grabbedtext = ClipGet()

$output = ""
$found = 0

For $m = 0 to UBound ($glossaryfilelines) - 1

If $found = 0 Then
If StringCompare ($grabbedtext, $glossaryfilefirstcolumn[$m], 1) = 0 Then
; If $grabbedtext = $glossaryfilefirstcolumn[$m] Then
$output = $glossaryfilesecondcolumn[$m]
$found = 1
EndIf
EndIf

Next

If $found = 0 Then
MsgBox (0, "No translation found!", "TransVoo could not find a translation for [" & $grabbedtext & "].", 0)
; Send ("{RIGHT}")
Else
ClipPut ($output)
; Send ("{RIGHT}")
Sleep ("100")
Send ("^v")
Sleep ("100")
; Send ("{LEFT}")
; Send ("{RIGHT}")
; Send ("{ENTER}")

EndIf

EndFunc

#cs

Func seekandkeep ()

Send ("+{TAB}")
Send ("^c")
$grabbedtext = ClipGet()

$output = ""
$found = 0

For $m = 0 to UBound ($glossaryfilelines) - 1

If $found = 0 Then
If StringCompare ($grabbedtext, $glossaryfilefirstcolumn[$m], 1) = 0 Then
; If $grabbedtext = $glossaryfilefirstcolumn[$m] Then
$output = $glossaryfilesecondcolumn[$m]
$found = 1
EndIf
EndIf

Next

If $found = 0 Then
MsgBox (0, "No translation found!", "TransVoo could not find a translation for [" & $grabbedtext & "].", 0)
Send ("{TAB}")
Else
ClipPut ($output)
ToolTip ("[" & $output & "] is on the clipboard")
Send ("{TAB}")
EndIf

EndFunc

#ce
When I press the hotkey, it should run the function, but I don't see any of those actions (left, right, F2, copy, etc) happening on my screen. After a second or two, I get the "No translation found!" error message (which is logical, since the relevant content was not copied in the first place).

I was hoping that there was something mysterious that I needed to do to make ensure that the sent keys don't disappear into a void when that program's window is the active window.

Samuel

Edited by leuce
Posted

Maybe when u start the .au3 the Window its not on the top or its not focused.

Thanks, that is good thinking, but in my case the window is active and the cursor is in the correct position in that program.

Posted (edited)

Have you considered using the Control* functions?

For example ControlSend, ControlSetText, ControlGetText?

No, but following your post I tried to see if I can get control names out of the program. The answer is that the position into which the keys must be sent, don't have its own control name.

Let me use Excel by analogy: imagine that a single cell does not have it's own control name (even though that cell is the position from which the sent keys must work), and that a cell only has a control name if you had pressed F2 and your cursor is inside the cell, and that otherwise the entire worksheet as a whole has a control name. It is exactly that in LocStudio.

This test script does nothing in LocStudio:

 

Sleep ("2000")
ControlSend ("Microsoft Localization Studio", "", "[CLASS:CEditGrid; INSTANCE:1]", "{LEFT}", 0)
Sleep ("1000")
ControlSend ("Microsoft Localization Studio", "", "[CLASS:CEditGrid; INSTANCE:1]", "{RIGHT}", 0)
Edited by leuce
Posted

I'm not familiar with the app but is there no other way of manipulating whatever files it uses, instead of the actual GUI?

If only. Practically everything in this program is done with the mouse -- there are essentially no keyboard shortcuts whatsoever. Thankfully I don't get many jobs in this dinosaur.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...