50行VBS代码实现自动朗读剪切板内容
Dim oClipboard, sapi, message, oldmessage, i
i = 0
Set oClipboard = New clsClipboard
message = oClipboard.GetText
oldmessage = message
Set sapi= CreateObject("sapi.spvoice")
Set sapi.Voice = sapi.GetVoices.Item(2) ''可以用这个Item的参数改成其他tts语音(Voice)
Do Until i=100
message = oClipboard.GetText
If message <> oldmessage Then sapi.Speak message
oldmessage = message
i = i+1
WScript.Sleep 1000
Loop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''' Subs / Classes / Functions '''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Class clsClipboard
''''' This class is used for manupilting the Windows clipboard.
''''' Under some versions of windows you may be prompted with a UAC message box
''''' before continuing. For an original copy of the example file showing how to
''''' call this class and other interesting scripts goto www.RichSchreiber.com
Private oHTML
Private Sub Class_Initialize
Set oHTML = CreateObject("InternetExplorer.Application")
oHTML.Navigate ("about:blank")
End Sub
' Get text from Clipboard
Public Property Get GetText()
GetText = oHTML.Document.ParentWindow.ClipboardData.GetData("Text")
End Property
Private Sub Class_Terminate
oHTML.Quit
Set oHTML = Nothing
End Sub
End Class
为了防止IE烦人的剪切板访问安全提示,可以在Internet选项-安全-自定义级别-脚本-允许对剪切板进行编程访问-选择启用,当想要关闭此程序时使用如下命令:
taskkill /fi "imagename eq cscript.exe"
taskkill /fi "imagename eq wscript.exe"
评论已关闭