【问题标题】:Why does my script cause the Ctrl key to be permanently active?为什么我的脚本会导致 Ctrl 键永久激活?
【发布时间】:2015-01-26 14:48:13
【问题描述】:

当我按下 Ctrl + 1Ctrl + 2 等时,我的 AutoIt 脚本会粘贴字符串。

Func copyPasta1()
   Send($texts[1], 1)
EndFunc
Func copyPasta2()
   Send($texts[2], 1)
EndFunc
...    
HotKeySet("^" & $keys_arr[2], "copyPasta" & ($i - 1))

有时 Ctrl 键会被锁定,因此整个系统的行为就像我连续按下 Ctrl 一样。按 Ctrl 即可解决。

我尝试改用 Shift,但随后 Shift 被锁定。有人对此有解决方案吗?我的脚本:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <Math.au3>

HotKeySet("^q", "end")

Func end()

    SplashTextOn("", "Programm wird beendet", 200, 40, -1, -1, 1, "", 10, 600)
    Sleep(1000)
    SplashOff()
    Exit

EndFunc

Func copyPasta1()
    Send($texts[1], 1)
EndFunc
Func copyPasta2()
    Send($texts[2], 1)
EndFunc
Func copyPasta3()
    Send($texts[3], 1)
EndFunc
Func copyPasta4()
    Send($texts[4], 1)
EndFunc
Func copyPasta5()
    Send($texts[5], 1)
EndFunc
Func copyPasta6()
    Send($texts[6], 1)
EndFunc
Func copyPasta7()
    Send($texts[7], 1)
EndFunc
Func copyPasta8()
    Send($texts[8], 1)
EndFunc
Func copyPasta9()
    Send($texts[9], 1)
EndFunc

; read config File
Local $hFileOpen = FileOpen(@WorkingDir & "\config.cfg", $FO_READ)

If $hFileOpen = -1 Then

    MsgBox(1, "", "Keine config Datei gefunden.")
    Exit

EndIf

Global $texts[12]

$sFileRead = FileRead($hFileOpen)
FileClose($hFileOpen)
$arr1 = StringSplit($sFileRead, "#TASTE:", 1)

For $i = 2 To _Min($arr1[0], 10)

    $arr2 = StringSplit($arr1[$i], "#SATZ:", 1)

    If $arr2[0] == 2 Then

        $keys_arr = StringSplit($arr2[1], '"', 1)
        $texts_arr = StringSplit($arr2[2], '"', 1)

        If $keys_arr[0] == 3 And $texts_arr[0] == 3 Then

            HotKeySet("^" & $keys_arr[2], "copyPasta" & ($i - 1))
            $texts[$i - 1] = $texts_arr[2]

        EndIf

    EndIf

Next

SplashTextOn("", "Programm gestartet", 200, 40, -1, -1, 1, "", 10, 600)
Sleep(1000)
SplashOff()

While 1
    Sleep(1000)
WEnd

Exit

【问题讨论】:

  • 发送 Send("{CAPSLOCK off}") 作为第二个命令怎么样?
  • @Xenobiologist 没有帮助。大写锁定未激活,它与 shift 键完全一样,将被永久按下,但没有大写锁定。
  • 检查以确保您没有在控制面板项目 > 轻松访问中心 > 使键盘更易于使用下打开粘滞键

标签: windows send autoit ctrl


【解决方案1】:

这是解决方案;你只需要添加这个函数,它来自http://www.autoitscript.fr/wiki/FAQ#Pourquoi_la_touche_Ctrl_reste_enfonc.C3.A9e.2C_apr.C3.A8s_que_j.27ai_lanc.C3.A9_mon_script_.3F

#include < Misc.au3 >
;Envoi la chaîne $ss après que les touches Shift Alt et Ctrl sont relachées. Optionnellement, donne une erreur après 1 sec si aucune de ces touches reste enfoncée.
;Nécessite d'inclure misc.au3 dans le script pour la fonction _IsPressed.
Func _SendEx($ss, $warn = "")
  Local $iT = TimerInit()

  While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
    If $warn <> "" And TimerDiff($iT) > 1000 Then
        MsgBox(262144, "Avertissement", $warn)
    EndIf
    Sleep(50)
  WEnd
  Send($ss)
EndFunc ;==>_SendEx

上面的cmets可以翻译:

在 Shift、Alt 和 Ctrl 键被释放后发送$ss 字符串。如果这些键均未按下,则可选择在 1 秒后返回错误。 _IsPressed() 需要 Misc.au3


并使用_SendEx("Your text") 而不是Send("Your text")

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-19
  • 2012-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多