This should work:
local ui = require "ui"
local sys = require "sys"
local cmd = require "console"
local ffi = require "c"
local consoleshow = false
local c_kernel = ffi.Library("kernel32.dll")
local c_user = ffi.Library("user32.dll")
c_user.ShowWindow = "(ii)B" -- ShowWindow: arguments(int (HWND(intptr)));int hCmdShow);returns(int(BOOL))
c_kernel.GetConsoleWindow = "()i" -- GetConsoleWindow: returns(int(HWND))
local c_kernel_sw_hide = ffi.Value("int", 0)
local c_kernel_sw_show = ffi.Value("int", 5)
local function updateconsole()
if consoleshow then
c_user.ShowWindow(c_kernel.GetConsoleWindow(), c_kernel_sw_show)
cmd.writeln("Console state: shown")
else
c_user.ShowWindow(c_kernel.GetConsoleWindow(), c_kernel_sw_hide)
cmd.writeln("Console state: hidden")
end
end
cmd.writeln("ConsoleToggleExample")
updateconsole()
local Window = ui.Window("WINDOW", "fixed",0,0)
Window.bgcolor = "15790320"
Window:center()
Window.x = Window.x - 128
Window.y = Window.y - 64
Window.width = 256
Window.height = 128
Window:show()
local console_button = ui.Button(Window,"Toggle console",80,48,96,32)
console_button.onClick = function()
consoleshow = not consoleshow
updateconsole()
end
while Window.visible do
ui.update()
end
At first the console is hidden, but when you press the button it appears.
The functional part is only the updateconsole() function.