Hi everyone !
I'm actually trying to make a game in Excel, coded in VBS (I know, this is crazy ), and I use the API "GetAsyncKeyState" in order to catch what keys are pressed :
It works perfectly, except when the Excel window is activated (i.e. foreground) : GetAsyncKeyState doesn't catch keys anymore. Excel seems to keep it for himself, and don't share it with the System...
I already tried to disable the Excel DataEntryMode, but my problem's still here...
Is there a way to disable this Excel's stupid behaviour, or making GetAsyncKeyState work better ?
Thanks for all your replies.
pacman
I'm actually trying to make a game in Excel, coded in VBS (I know, this is crazy ), and I use the API "GetAsyncKeyState" in order to catch what keys are pressed :
Code:
Public Const VK_UP = &H26
Public Const VK_DOWN = &H28
Public Const VK_LEFT = &H25
Public Const VK_RIGHT = &H27
Public Const VK_DELETE = &H2E
Set oDyn = CreateObject("DynamicWrapper")
oDyn.Register "User32.dll", "GetAsyncKeyState", "i=l", "r=t"
Set ExcelApp = WScript.CreateObject("EXCEL.application")
ExcelApp.Visible = True
ExcelApp.workbooks.Add
ExcelApp.sheets(1).Activate
ExcelApp.DataEntryMode = True
WScript.Echo "Debut"
continue = True
While (continue)
If (oDyn.GetAsyncKeyState(VK_UP) = -32767) Then
WScript.Echo "UP"
End If
If (oDyn.GetAsyncKeyState(VK_DOWN) = -32767) Then
WScript.Echo "DOWN"
End If
If (oDyn.GetAsyncKeyState(VK_LEFT) = -32767) Then
WScript.Echo "LEFT"
End If
If (oDyn.GetAsyncKeyState(VK_RIGHT) = -32767) Then
WScript.Echo "RIGHT"
End If
If (oDyn.GetAsyncKeyState(VK_DELETE) = -32767) Then
continue = False
End If
WScript.Sleep(50)
Wend
Set oDyn = Nothing
ExcelApp.DisplayAlerts = False
ExcelApp.Quit
ExcelApp.DisplayAlerts = True
Set ExcelApp = Nothing
I already tried to disable the Excel DataEntryMode, but my problem's still here...
Is there a way to disable this Excel's stupid behaviour, or making GetAsyncKeyState work better ?
Thanks for all your replies.
pacman