Problem with Window.event.keyCode and .dat memory read VBS hta

46 views Asked by At

Basically, what I am trying to do is to create a system where I can store keycode in a .dat file named Bindings and use them to define the key associated with an action. For example the key escape is translated into keyCode format into "27" and in hta in the script tag if you create a sub named document_OnKeyDown the variable Window.event.keyCode is created with the a keyCode associated with it for example if I press escape the var Window.event.keyCode = 27 but when I define the action to close the page to the keyCode in the aforementioned file it suddenly the keyCode 27 of the Bindings file is not equal to the 27 of Window.event.keyCode for some reason.

So I tried and this is what happened:

The bindings file

close 27
pause 32
loop 82
minus 37
plus 39
up 38
down 40

The script in my hta included in the <script> tag

' to read in memory
Function Read(Path, Var)
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set File = FSO.OpenTextFile(Path, 1) ' 1 = reading, 2 = write, 8 = write at the end

    allData = File.readall
    File.Close
    For Each ln In Split(allData, vbCrLf)
        VarName = Split(ln, " ", 2)(0)
        If VarName = Var Then
            output = Split(ln, " ", 2)(1)
            Exit For
        End If
    Next

    ' memory management (vbs does not have one for objects only vars have one)
    Set File = Nothing
    Set FSO = Nothing

    ' return
    Read = output
End Function

Key_close = Read("C:\Users\[login name]\Desktop\Repos\[my repo]\dat\Bindings.dat", "close")

' Called each time a key is pressed
Sub document_OnKeyDown
    lnum = Window.event.keyCode
    If Window.event.keyCode = Key_close Then msgbox "worked"
    If Window.event.keyCode = 27 Then
        msgbox Window.event.keyCode & vbCrLf & 27 & vbCrLf & "Window.event.keyCode = 27"
        If 27 = Key_close Then 
            msgbox 27 & vbCrLf & Key_close & vbCrLf & "27 = Key_close"
            If Window.event.keyCode = Key_close Then msgbox "Window.event.keyCode = Key_close"
            If lnum = Key_close Then msgbox "lnum = Key_close"
        End If
    End If
End Sub

The result was only two msgbox's the first one being

27
27
Window.event.keyCode = 27

The second one being:

27
27
27 = Key_close

But nothing else I do not understand

Why is 27=27 true but 27=27 not true like whaaat?

0

There are 0 answers