Vbscript Visual Basic脚本-按键检测?
按下F1键后,我想终止程序。 不确定如何编写do while循环。 有什么想法吗Vbscript Visual Basic脚本-按键检测?,vbscript,keyboard,detection,Vbscript,Keyboard,Detection,按下F1键后,我想终止程序。 不确定如何编写do while循环。 有什么想法吗 Set WshShell = WScript.CreateObject("WScript.Shell") Do While {F1} is not pressed '... Loop 这在普通VBScript中是不可能的,但您可以让它与以下脚本一起工作: 试验 子检查键 如果window.event.keyCode=112,则self.close() 端接头 ... 我使用了一个混合VBS脚本,其中嵌入了一个使
Set WshShell = WScript.CreateObject("WScript.Shell")
Do While {F1} is not pressed
'...
Loop
这在普通VBScript中是不可能的,但您可以让它与以下脚本一起工作:
试验
子检查键
如果window.event.keyCode=112,则self.close()
端接头
...
我使用了一个混合VBS脚本,其中嵌入了一个使用adodb.stream的小型C#程序
此示例使用每个步骤更新剪贴板(例如登录),但可以轻松修改它以触发其他事件
您可以删除清理行,并且.exe可以放在temp目录中
为简洁起见,十六进制部分已被截断,但整个文件可在
Dim wsh,exe,HexKeyCode
设置wsh=CreateObject(“Wscript.Shell”)
设置fso=CreateObject(“Scripting.FileSystemObject”)
HexKeyCode=“70”F1=70 F12=7B ALT-GR=A5 ESC=1B
exe=“按F1键以逐步执行脚本,直到我消失。exe”
如果不存在fso.FileExists(exe),则调用create\u binary\u file_
'每次按F1时更新剪贴板
'############################################
wsh.Run“cmd.exe/c”“&exe&”“&HexKeyCode,0,TRUE
wsh.Run“cmd.exe/c echo 1 | clip”,0,TRUE
wsh.Run“cmd.exe/c”“&exe&”“&HexKeyCode,0,TRUE
wsh.Run“cmd.exe/c echo 2 | clip”,0,TRUE
“随意清理
'################
fso.DeleteFile exe
子创建二进制文件
'########################
hex=“4D5A90…0000”
'用于二进制文件写入
'#########################
dim str
set str=WScript.CreateObject(“adodb.stream”)
str.type=2
str.charset=“iso-8859-1”
str.open
对于x=1至len(十六进制)步骤2
高=asc(中(十六进制,x,1))
如果高<58,则
高u=(高-48)*16
其他的
高u=(高-55)*16
如果结束
低=asc(中(十六进制,x+1,1))
如果低<58,则
低电平=(低电平-48)
其他的
低电平=(低电平-55)
如果结束
str.writeText(chrW(高+低))
下一个
str.saveToFile exe,2
str.close
端接头
我认为这在VBScript中是不可能的
<head>
<title>Test</title>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="Test"
>
</head>
<script language="VBScript">
Sub CheckKey
If window.event.keyCode = 112 Then self.close()
End Sub
</script>
<body onKeyUp="CheckKey">
...
</body>
Dim wsh, exe, HexKeyCode
Set wsh = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
HexKeyCode = "70" 'F1=70 F12=7B ALT-GR=A5 ESC=1B
exe = "Press F1 to step script until I disappear.exe"
if not fso.FileExists(exe) then call create_binary_file_
'EACH TIME F1 IS PRESSED UPDATE THE CLIPBOARD
'############################################
wsh.Run "cmd.exe /c """ & exe & """ " & HexKeyCode, 0, TRUE
wsh.Run "cmd.exe /c echo 1| clip", 0, TRUE
wsh.Run "cmd.exe /c """ & exe & """ " & HexKeyCode, 0, TRUE
wsh.Run "cmd.exe /c echo 2| clip", 0, TRUE
'OPTIONAL TIDY-UP
'################
fso.DeleteFile exe
sub create_binary_file_()
'########################
hex_="4D5A90...0000"
'FOR THE BINARY FILE WRITE
'#########################
dim str
set str = WScript.CreateObject("adodb.stream")
str.type = 2
str.charset = "iso-8859-1"
str.open
for x = 1 to len(hex_) step 2
high_ = asc(mid(hex_,x,1))
if high_ < 58 then
high_ = (high_-48)*16
else
high_ = (high_-55)*16
end if
low_ = asc(mid(hex_,x+1,1))
if low_ < 58 then
low_ = (low_-48)
else
low_ = (low_-55)
end if
str.writeText(chrW(high_ + low_))
next
str.saveToFile exe, 2
str.close
end sub