我的代码:
HotKeySet("^v","ClipboardToKeystroke")
While 1
WEnd
Func ClipboardToKeystroke()
Send(ClipGet(),1)
EndFunc
不幸的是,它不像我期望的那样。对于单行,它运行良好,但对于多行,它发送enter的副本。例如:
原文:
这是第1行 这是第二行
自动按键后:
这是第1行
这是第二行
还有一件事,发送击键后Ctrl键也有问题,似乎Ctrl键保持不变,我必须再次按下Ctrl键才能释放它。
那么有解决方法吗?
答案 0 :(得分:4)
我一直忙着这个,直到我按照你的预期工作。这是最终产品:
有关于代码中发生事情的方式和原因的解释。我不得不使用这些年来我提到的许多小“伎俩”。
#include <Misc.au3>
HotKeySet("^v","ClipboardToKeystroke")
While 1
Sleep(50) ; If you forget this, your program takes up max CPU
WEnd
Func ClipboardToKeystroke()
HotKeySet("^v", "Dummy") ; This unregisters the key from this function, and sets it on a dummy function
While _IsPressed("11") Or _IsPressed("56") ; Wait until both the ctrl and the v key are unpressed
Sleep(50)
WEnd
$clipboard = ClipGet()
$clipboard = StringStripCR($clipboard) ; A newline consists of 2 characters in Windows: CR and LF.
;If you type a CR, Windows understands it as an attempt to type CRLF.
; If you type LF, same thing. So if you type CR and then LF, it is interpreter as CRLFCRLF. Thus two newlines.
Send($clipboard, 1)
HotKeySet("^v", "ClipboardToKeystroke")
EndFunc
Func Dummy()
; Do nothing, this prevents the hotkey to calling the ClipboardToKeystroke function a lot when you hold the key down too long
EndFunc