简体   繁体   中英

AutoHotkey's Loop (read file contents) issues related to “+” symbol

Referring to Loop (read file contents) , a quite strange thing happens every time I use a code like this one to run a script:

^+k::
{
    Gosub, MySub
}
Return

MySub:
{
    Send, +{Enter}
    Loop, read, C:\MyFile.txt
    {   
        temp = %A_LoopReadLine%
        Send, %temp%
        Send, +{Enter}
    }
}
Return

MyFile.txt is a simple text file where sometimes the "plus" symbol ( + ) is used together with normal letters and numbers.

Despite of this, however, what I see if I run the hotkey on an empty text file, either a Notepad or Microsoft Word blank sheet, is that every + is replaced by an underscore ( _ ), an exclamation mark ( ! ) or a question mark ( ? ). I've seen an occurrence with a dollar symbol ( $ ) replacement, too.

I tried to debug it printing on screen a message box with

MsgBox, %temp%

before sending text and it shows the original content of MyFile.txt perfectly. Thus the issue should be on Send rather than on file reading.

The content of my file is something like this (repeated for about 20 rows more):

+---------------------------------
120001267381  ~ TEXT 0 10/20/18 VARIABLE  word text -> numbers: 17,000 x 108.99 | 109.26 x 15,000 ///  number = +5.500% some text
+---------------------------------
120001267381  ~ TEXT 0 10/20/18 VARIABLE  word text -> numbers: 17,000 x 108.99 | 109.26 x 15,000 ///  number = +5.500% some text
+---------------------------------
120001267381  ~ TEXT 0 10/20/18 VARIABLE  word text -> numbers: 17,000 x 108.99 | 109.26 x 15,000 ///  number = +5.500% some text
+---------------------------------
120001267381  ~ TEXT 0 10/20/18 VARIABLE  word text -> numbers: 17,000 x 108.99 | 109.26 x 15,000 ///  number = +5.500% some text
+---------------------------------

What can be the cause of this?

Found the answer: due to the fact that + symbols read from my file are sent like pressing the Shift key, the output is amended by the pressing of such a key instead of sending the original symbol present in file.

In order to send the original content of my file without triggering special hotkeys, I have to use SendRaw instead of Send , like in this example:

^+k::
{
    Gosub, MySub
}
Return

MySub:
{
    Send, +{Enter}
    Loop, read, C:\MyFile.txt
    {   
        temp = %A_LoopReadLine%
        SendRaw, %temp%
        Send, +{Enter}
    }
}
Return

Here's an updated version that pastes using CTRL-V instead of Send to "retype" rows of data:

^+k::
{
    Gosub, MySub
}
Return

MySub:
{
    Send, +{Enter}
    Loop, read, C:\MyFile.txt
    {   
        temp = %A_LoopReadLine%
        Clipboard = %temp%   ; Write to clipboard
        Send, ^v+{enter}     ; Paste from clipboard
        Sleep 10             
; Short delay so it doesn't try to paste again before the clipboard has changed
; This check can get a lot more complex, but just increase it if 10 doesn't work
    }
}
Return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM