将剪贴板转换为击键 [英] convert clipboard to keystroke
问题描述
我的代码:
HotKeySet("^v","ClipboardToKeystroke")
While 1
WEnd
Func ClipboardToKeystroke()
Send(ClipGet(),1)
EndFunc
不幸的是,它的行为并不像我期望的那样.对于单行,它运行良好,但对于多行,它发送重复的输入.例如:
Unfortunately it doesn't behave like what I expect. For a single line, it works well but for multiple lines it send duplicate of enter. Eg :
原文:
这是第一行
这是第二行
This is the 1st line
This is the 2nd line
自动击键后:
这是第一行
这是第二行
还有一件事,发送击键后Ctrl键也有问题,似乎Ctrl键被按住,我必须再次按下Ctrl键才能释放它.
And one more thing, there is also a problem with the Ctrl key after send the keystroke, it seems the Ctrl key is hold and I have to press the Ctrl key again to release it.
所以有解决方法吗?
推荐答案
我一直忙于这件事,直到它像你期望的那样工作.这是最终产品:
I kept busy on this until I got it working like you would expect. This is the final product:
有关于代码中事情发生的方式和原因的解释.我不得不使用我多年来学到的很多小技巧".
There are explanations as to how and why things are happening in the code. I had to use a lot of little "tricks" I picked up over the years.
#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
这篇关于将剪贴板转换为击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!