如何在.hta文件处于后台时检测按键

时间:2014-10-03 19:51:48

标签: vbscript hta

我知道同一个问题可能有10个问题,但我看过它们并没有找到任何有用的答案。

我有一个.hta脚本,就像这样。

<head>
<title>Test</title>
<script language="VBScript">

Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strDirectory = "C:\Users\Owner\Desktop\Projects"
strFile = "\Project.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FolderExists(strDirectory) Then
        Set objFolder = objFSO.GetFolder(strDirectory)
    Else
        Set objFolder = objFSO.CreateFolder(strDirectory)
        WScript.Echo "Just created " & strDirectory
    End If

    If objFSO.FileExists(strDirectory & strFile) Then
        Set objFolder = objFSO.GetFolder(strDirectory)
    Else
        Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
    End If 

    set objFile = nothing
    set objFolder = nothing
    Const ForAppending = 8
    Set objTextFile = objFSO.OpenTextFile _
    (strDirectory & strFile, ForAppending, True)

    Sub CheckKey
     If window.event.keyCode = 112 Then
        objTextFile.WriteLine(Time & " - " & Date & ": ") & ("F1")
     End If
    End Sub
</script>
<body onKeyUp="CheckKey">
</body>
</head>

所以它检测到键F1(我用F1作为例子)并将它放在.txt文件中(所以我知道测试时按下了什么)。

然而,有一个问题。当我在没有选择.hta应用程序的情况下按F1时,它将无法检测到按键。所以我想知道如何把它放在后台,所以即使不在应用程序上它仍然会检测到按键。如果那是不可能的,我可以纯粹在VBScript中做到吗? - 谢谢

0 个答案:

没有答案