1

あるプログラム (IE) から電子メールの件名フィールドにコピーされるはずの文字列に、次のような間違いが含まれていることがあります。

ただし、変数 subject のメッセージ ボックス (以下を参照) は常に正しいものです。

subject= %protocol% , %LSN% , %Site% , %Requisition%

ただし、コードを実行すると:

10 回に 1 回、件名フィールド内に文字列が正しく配置されていません。

私が期待する:

プロトコル C16019、LSN (102707)、サイト 22902、要求 102921403

私は得る:

プロトコル c16019 (大文字の C の代わりに小文字の C )、lSN (&02707° ( 1 の代わりに %、の代わりに °) )、サイト é2902 ( 2 の代わりに é )、要求 &02921403(1 の代わりに &)

AHK が私の特殊文字 (F1-F12 キーの下の文字行) を使用しているか、シフト ボタンがアクティブになっているようです。

これを解決する理由と方法を教えてください。

私はどこかで、controlsendが常に機能するとは限らず、それは既知の問題であることを読みました。

補足: 電子メール アドレスの @ が常に送信先フィールドに入力されていない別のスクリプトでも、これを確認しています。

私のコード:

    Home::

    pwb := WBGet()
    pTable:= pwb.document.GetElementsByTagName("Table") [4] ;outerHTML ;Set Tag name and Array value
    Loop, % pTable.rows.length {
    LSN_1:= pTable.rows[9] .GetElementsByTagName("TD") [1].outerHTML ; LSN

    protocol_1:= pTable.rows[9] .GetElementsByTagName("TD") [3].outerHTML ; Protocol

    Site_1:=pTable.rows[10] .GetElementsByTagName("TD") [1].outerHTML ; Site

    Requisition_1:=pTable.rows[12] .GetElementsByTagName("TD") [3].outerHTML ;   Requisition


    StringTrimLeft, NLSN, LSN_1, 6   ;trims 6 characters from left  ( <TD> >)
    StringTrimRight, fLSN, NLSN, 5   ;trims 5 characters from right (<TD> )

    StringTrimLeft, Nprotocol, protocol_1, 6
    StringTrimRight, fprotocol, Nprotocol, 5


    StringTrimLeft, Nsite, site_1, 6
    StringTrimRight, fsite, Nsite, 5


    StringTrimLeft, NRequisition, Requisition_1, 6
    StringTrimRight, fRequisition, NRequisition, 5


    Requisition= requisition %fRequisition%

    sleep,10

    LSN= LSN (%fLSN%)  ; essential that this variable is put into brackets

    sleep,10

    Site= site %fsite% ; "site" has to be put before the string

    sleep,10

    Protocol= protocol %fprotocol% ;"protocol" has to be put before the string

    sleep,10

    subject= %protocol% , %LSN% , %Site% , %Requisition%

    sleep,150

;the variable in Msgbox is always correct here

    ;send the contents of subject into the subject of outlook
    controlFocus, RichEdit20WPT4, ahk_class rctrl_renwnd32
    controlSend, RichEdit20WPT4, {end} , ahk_class rctrl_renwnd32 ; send to the end of subject field
    controlSendRaw, RichEdit20WPT4, %subject%, ahk_class rctrl_renwnd32
    sleep,100
    subject :=""
    return
    } 

文字列は 10% ~ 20% の確率で正しくありません。

注意してください、私はまったくの初心者です。スクリプトの作成を学び、約 2 週間試してみました。このスクリプトが常に 100% 機能しない理由がわかりません。

4

1 に答える 1

1

ControlSend の代わりに ControlSendRaw を使用している理由はありますか? これはあなたの問題かもしれません。

ControlSendRawを引き続き使用する場合は、 BlockInput、 On および BlockInput、 Off 周囲のコードを使用して、キーの押下による干渉を制限することをお勧めします。

上に投稿したもののクリーンアップされたバージョンは次のとおりです。

Home::

    pwb := WBGet()
    pTable := pwb.document.GetElementsByTagName("Table") [4] ;outerHTML ;Set Tag name and Array value
    LSN_1 := pTable.rows[9] .GetElementsByTagName("TD") [1].outerHTML ; LSN
    protocol_1:= pTable.rows[9] .GetElementsByTagName("TD") [3].outerHTML ; Protocol
    Site_1:=pTable.rows[10] .GetElementsByTagName("TD") [1].outerHTML ; Site
    Requisition_1:=pTable.rows[12] .GetElementsByTagName("TD") [3].outerHTML ;   Requisition  

    subject := "protocol " trimVar(protocol_1) " , LSN (" trimVar(LSN_1) ") , Site " trimVar(Site_1) " ,  Requisition " trimVar(Requisition_1)

    ;send the contents of subject into the subject of outlook
    controlFocus, RichEdit20WPT4, ahk_class rctrl_renwnd32
    controlSend, RichEdit20WPT4, {end} , ahk_class rctrl_renwnd32 ; send to the end of subject field
    BlockInput, On
    controlSendRaw, RichEdit20WPT4, %subject%, ahk_class rctrl_renwnd32
    BlockInput, Off
    sleep,100
    subject :=""
return

trimVar(x) { 
    StringTrimLeft, x, x, 6   ;trims 6 characters from left  ( <TD> >)
    StringTrimRight, x, x, 5   ;trims 5 characters from right (<TD> )
    Return x
}

おそらく、行と列のインデックスを見つけることからコードを残して、ループの本当の必要性を見ませんでした? または、編集して元に戻すのに十分なほど簡単な目的があるかもしれません。これでランダムキャラクターの問題が修正されることを願っています. そうでない場合は、ControlSendRaw の代わりに通常の ControlSend を使用してみて、BlockInput を削除してください...

このスクリプトを使用してテキストを挿入するときに、Outlook で積極的に電子メールを入力している可能性があるように思えます。この場合、次のコードは、ホットキーの代わりにHotStringを使用してアクティブ化し、ControlSend を必要としなくなります。

#IfWinActive ahk_class rctrl_renwnd32 ;The code below will only work if Outlook is the Active application
::insertlsn:: ;Type HotString to activate code below
    pwb := WBGet()
    pTable := pwb.document.GetElementsByTagName("Table") [4] ;outerHTML ;Set Tag name and Array value
    LSN_1 := pTable.rows[9] .GetElementsByTagName("TD") [1].outerHTML ; LSN
    protocol_1:= pTable.rows[9] .GetElementsByTagName("TD") [3].outerHTML ; Protocol
    Site_1:=pTable.rows[10] .GetElementsByTagName("TD") [1].outerHTML ; Site
    Requisition_1:=pTable.rows[12] .GetElementsByTagName("TD") [3].outerHTML ;   Requisition

    subject := "protocol " trimVar(protocol_1) " , LSN (" trimVar(LSN_1) ") , Site " trimVar(Site_1) " ,  Requisition " trimVar(Requisition_1)

    SendInput, %subject%
return 

trimVar(x) { 
    StringTrimLeft, x, x, 6   ;trims 6 characters from left  ( <TD> >)
    StringTrimRight, x, x, 5   ;trims 5 characters from right (<TD> )
    Return x
}

最終的な解決策の 1 つは、OutLook COM オブジェクトを使用することです。すでに IE ComObjects を使用しているため、この形式についてはある程度理解しているはずです。この方法を実装することを選択した場合、ここに優れたリファレンスがあります。

于 2015-06-10T20:21:54.540 に答える