Nifty gui console not receiving key events

I’ve added a nifty console to my game using the samples here:

I’ve added it to a popup which is added to the current screen on a key press. This works fine, and I can output text to the console no problem using the Console class, however I cannot type any text in the console. If it’s helpful to know, the rest of my key bindings still work (such as movement controls), whilst I can easily disable these it may provide some insight into the problem.

It seems to me that the popup containing the console should be modal, that is prevent anything else from gaining any focus until the popup is closed. Is this right??

Ok fixed it, solution was to add the popup using the following when the player first opens the console:

if (consolePopup == null){
currentScreen.addPopup(nifty.createPopup("popupConsole"), null);
consolePopup = currentScreen.getTopMostPopup();

console = consolePopup.findNiftyControl("console", Console.class);
ConsoleCommands consoleCommands = new ConsoleCommands(nifty, console);

// create another command (this time we can even register arguments with nifty so that the command completion will work with arguments too)
ConsoleCommand showCommand = new ShowCommand();
consoleCommands.registerCommand("show stats", showCommand);

// finally enable command completion
} else {
currentScreen.addPopup(consolePopup, null);

rather than create it first then add the created console on key press. I believe the console object required the console to be attached to a screen when it is created for it to function correctly.

The issue I'm having now is that if I console.output() anything then subsequent outputs are not shown (even echoing of commands entered in the console don't show). Any ideas?

It’s not my intention to bump, it’s just that I suspect this problem could be related to mine.

First of all, my intention is to get a console in a popup persisten through screens. In other words I want to have a console at any time in the game shown by pressing [ESC].

I begin by loading the XML file in the “mainScreen”. At this point I can perfectly use the console, which I toogle(add and close) using the [ESC] key. At this point I have already created a “loginPopup”. When I login to the server and I receive the player information I gotoScreen(“gameScreen”). Now I can toogle the “consolePopup” element stored before and it shows and hides fine, keeping it’s previous state, but it doesn’t get any input from the keyboard.

My guess is, as @gb056 said, is that the console gets binded to the “mainScreen” input, and this is no longer receiving any events.

I’ve already tried everything I’ve seen all over the web and nothing worked…

I am trying to achieve this the wrong way? I am not experienced with nifty-gui…

Any help would be sincerely appreciated.

An extract from the main XML


16 <screen id=“mainScreen”>

17 <layer id=“mainLayer” childLayout=“center”>

18 <panel id=“mainPanel” childLayout=“vertical” />

19 </layer>

20 </screen>


22 <screen id=“gameScreen”>

23 <layer id=“gameLayer” childLayout=“absolute”>

24 <panel childLayout=“absolute” x=“8” y=“10” width=“554” height=“92”

25 visibleToMouse=“true”>

26 <control x=“5” y=“0” width=“540” height=“92” id=“gameLog”

27 name=“listBox” vertical=“optional” horizontal=“optional”

28 displayItems=“6” wrap=“true” selectionMode=“Disabled” />

29 </panel>

30 <panel childLayout=“absolute” x=“18” y=“108” width=“535”

31 height=“18”>

32 <control x=“0” y=“0” width=“535” height=“18” id=“gameConsole”

33 name=“textfield” text="" />

34 </panel>

35 </layer>

36 </screen>


74 <popup id=“consolePopup” childLayout=“center”>

75 <panel align=“center” childLayout=“center” valign=“center”

76 width=“95%”>

77 <control id=“console” name=“nifty-console” align=“center”

78 lines=“40” valign=“center”>

79 <effect>

80 <onCustom name=“move” alternateEnable=“show” direction=“top”

81 inherit=“true” length=“200” mode=“in” startDelay=“0” />


83 <onCustom name=“move” alternateEnable=“hide” direction=“top”

84 inherit=“true” length=“200” mode=“out” startDelay=“0” />

85 </effect>

86 </control>

87 </panel>

88 </popup>


I’ve rolled my own popup system that (among other things) persists popups between various screens. It works by adding a layer on the screen and placing popups on that layer. Whenever you change screens it detects this and recreates the layer and any popups that were open.

Thank you @zarch. I know how to recreate everything on screen change, but what I need is to “reuse” the previus console control located in the previous popup. And if I just add the old popup or control the input does not work. So I see the element(popup and console) as I should but I can’t interact with it(or type) even though the cursos is placed in the textbox by using focus function.

Sorry, I can’t help you with that since I’ve moved to my own system now.

Thank you very much anyway @zarch.

So, does anyone know how to use the same console for the entire game, and through different screens, keeping it’s content or state?

I am feeling a little bit frustrated or even desperate about this…

Should I resolve this by putting the whole game under the same screen? It sounds crazy… but it’s the only thing I can come up with :frowning:

I’d give it a few days to give other people a chance to reply (void reads and replies here as well as several experienced users) before you start doing anything drastic :slight_smile:

I think people won’t help due to the simplicity of the problem. They may find it boring :frowning: or me stupid…

is this the answer I am looking for?

Maybe I was trying to solve the problem the wrong way… should I take this direction?

U need to remove currentScreen.processAddAndRemoveLayerElements();
At the moment you create the popup with currentScreen.addPopup(nifty.createPopup(“popupConsole”), null);
console events like key or input events are directed to the screen controller of the screen which is active.

Yes, another broken link.

I guess it ain’t that hard to simply google the topic and find it on the new forum, is it?