Community Forum

How to disable Keyboard Input?

Forum Overview >> Scripting

CategoryScripting
Created20.03.2011 20:47


Dennis Meise (Unknown) 20.03.2011 20:50
Hello,

is there any way to disable the keyboard input in the game?
i am currently working on a kind of userinput where the user can chose a filename for saving some data.

everything works fine but if the user for example presses "e" he is outside the vehicle.

How did you manage it in your chat functionality?

Stefan Geiger - GIANTS Software 21.03.2011 10:10
The Input currently is disabled if a gui is active, which is the case for the chat gui.


To do this, you first need to create an empty gui. To do this you need to create an xml file with this code.

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<GUI>
<GuiElement/>
</GUI>

Then you need to load this xml file:
local guiName = g_currentModName.."_emptyGui";
g_gui:loadGui(g_currentModDirectory.."emptyGui.xml", guiName);


When you want to disable the input and show your input gui, you can enable the empty gui with this code:


g_gui:showGui(guiName);

When you are finished, you can close your gui again with:
g_gui:showGui("");


Maybe you want to check, if no other gui is active before you enable your own gui.
This you can do with:

if g_gui.currentGui ~= nil then
....

You can also store the value g_gui.currentGuiName to a variable and use it later to restore the current gui.
E.g.
local prevName = g_gui.currentGuiName;
g_gui:showGui(guiName);

....

-- restore the last gui
g_gui:showGui(prevName);

Dennis Meise (Unknown) 21.03.2011 14:44
thank you very much, this seems to work. at least the original gui disappears and i found out that the draw() method of the mod is disabled.

But the keyEvent method is also disabled. And this one was responsible for the user input and stopped the form if "ENTER" was hit.

do i have to write my own input gui now (and if so how does this work) or is there a way to enable the KeyEvent?

Dennis Meise (Unknown) 21.03.2011 18:15
Sorry, there was a little mistake in my code, that caused that error.

i've fixed that and now i get the following error:

"Lua: Error running function: mouseEvent
D:/code/lsim2011/build/finalbin/dataS/scripts/gui/ShopScreen.lua(180) : attempt to index local 'buyButton' (a nil value)"


this is my code:

function courseplay:load(xmlFile)

....


self.lastGui = nil
self.currentGui = nil
self.input_gui = "inputGui";

g_gui:loadGui(Utils.getFilename("../aacourseplay/emptyGui.xml", self.baseDirectory), self.input_gui);
......

end

function courseplay:update(dt)

if self.user_input_active then
if self.currentGui == nil then
g_gui:showGui(self.input_gui);
self.currentGui = self.input_gui
end
else
if self.currentGui == self.input_gui then
g_gui:showGui("");
end
end

end

self.user_input_active is manually set and indicates that the user wants to type the filename for saving

The whole code is on github:
https://github.com/netjungle/courseplay

Th. Birrer (Ralf08) 22.11.2020 19:43
Hi people,
Is it still possible to open an empty gui to disable the keyboard?
I know, that new is another argument required (controller), but I cannot figure out, what I need to define in this controller, that I can open an empty gui.

As background information, I’m working on a simple gui for some user inputs, but I was not able to understand the in game gui functions. There are some mods with a gui, this guis look really nice, but my coding experience is not good enough for this. So I decided to try it the old school way with an overlay and some overlay buttons, together with the mouse input it is running as expected, but I have troubles with the key input.



Note: Log in to post. Create a new account here.