I am writing an ascent autopilot for the XR2 in Lua, and I need a way to send key combinations to the Ravenstar. I tried v:send_bufferedkey, but it takes only one input (keycode).
I attempted using nested while loops but I only got one key pressed, not both at the same time:
My next attempt was to send the key combo from a vb script:
Again, same result. The script runs, but the keys are not pressed at the same time. (In a landed Ravenstar, I get the "Hover doors are closed" message, showing that it received the A key, not the CTRL-A combo).
In the OrbiterSDK, SendBufferedKey takes 3 arguments:
How can I change it to also take the kstate argument?
Thanks in advance.
I attempted using nested while loops but I only got one key pressed, not both at the same time:
Code:
goal = 0
while goal < 1 do
control_key = v:send_bufferedkey(OAPI_KEY.LCONTROL)
while control_key ~= nil do
--control_key = v:send_bufferedkey(OAPI_KEY.LCONTROL)
a_key = v:send_bufferedkey(OAPI_KEY.A)
if a_key ~= nil then
control_key = nil
goal = 1
end
end
if goal > 0 then end
end
My next attempt was to send the key combo from a vb script:
Code:
-- Define the VBScript code
local vbscript = [[
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^a"
Set WshShell = Nothing
]]
-- Create a temporary VBScript file
local vbscriptFileName = os.tmpname() .. ".vbs"
local vbscriptFile = io.open(vbscriptFileName, "w")
vbscriptFile:write(vbscript)
vbscriptFile:close()
-- Execute the VBScript
os.execute("cscript " .. vbscriptFileName)
-- Delete the temporary VBScript file
os.remove(vbscriptFileName)
Again, same result. The script runs, but the keys are not pressed at the same time. (In a landed Ravenstar, I get the "Hover doors are closed" message, showing that it received the A key, not the CTRL-A combo).
In the OrbiterSDK, SendBufferedKey takes 3 arguments:
In Lua, it takes only one:int VESSEL::SendBufferedKey ( DWORD key, bool down = true, char * kstate = 0 )
In the interpreter, the send_bufferedkey method is implemented like this:res = v:send_bufferedkey(keycode)
Sends a keycode message to the vessel.
C++:
int Interpreter::v_send_bufferedkey (lua_State *L)
{
static char *funcname = "send_bufferedkey";
AssertMtdMinPrmCount(L, 2, funcname);
VESSEL *v = lua_tovessel_safe(L, 1, funcname);
int key = luamtd_tointeger_safe (L, 2, funcname);
int res = v->SendBufferedKey (key);
lua_pushnumber (L, res);
return 1;
}
How can I change it to also take the kstate argument?
Thanks in advance.
Last edited: