imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Enter and Backspace key don't work in text boxes (but imgui callbacks are successfully installed!)

Open PcChip opened this issue 2 years ago • 2 comments

[Latest ImGui Docking]
[Latest GLFW]
[Visual Studio 2019]

Hello,

using ImGui::InputText , it seems like ImGui ignores the enter and backspace keys

at first I thought it was a bug with the version of GLFW or ImGui I was using, so I updated to latest GLFW and latest Docking ImGui however it still happens

I verified all the ImGui callback handlers are being set, and even write a debug line when they are called,

however when I click the input text line, the enter and backspace key do not register any callbacks in ImGui!

Example: https://i.imgur.com/cZ4YEfH.png

I tried with the flag ImGuiInputTextFlags_EnterReturnsTrue and without

Thanks for any help you might have!

PcChip avatar Sep 26 '21 19:09 PcChip

`
void te2LUAModule::updateFrame(double dt)
{
	static const  ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue;
	static bool show = true;

	if (show)
	{
		ImGui::Begin("LUA", &show);
		ImGui::Text("LUA Command: ");
		ImGui::SameLine();
		static char command[256] = ""; 
		
		//io.KeyDown[io.KeyMap[ImGuiKey_Enter]));
		if(ImGui::InputText("", command, 256, flags))
		//ImGui::InputText("##command", command, 256);
		//if(ImGui::IsKeyPressed(ImGuiKey_Enter))
		{
			std::string input(command);
			memset(command, 0, 256);

			auto code_result = lua.script(input, [](lua_State*, sol::protected_function_result pfr) {
				// pfr will contain things that went wrong, for either loading or executing the script
				// Can throw your own custom error
				// You can also just return it, and let the call-site handle the error if necessary.
				return pfr;
				});

			std::cout << "\n";
			/*
			if (code_result.valid())
			{
				std::cout << "Success!\n";
			}*/
			if (!code_result.valid())
			{
				std::cout << "Failed!\n";
			}
			std::cout << "return status: " << (int)code_result.status() << "\n";
		}
		ImGui::End();
	}


}`

PcChip avatar Sep 26 '21 19:09 PcChip

I had the same issue and it was caused by calling ImGui_ImplGlfw_InitForOpenGL before setting my own GLFW input callbacks.

uk1324 avatar Jul 14 '22 22:07 uk1324

As answered, this was most likely due to Key callback not being registered or overridden by yours.

Not that CharCallback and KeyCallback are different. I would imagine your app overrode the Key callback and didn't chain properly.

I verified all the ImGui callback handlers are being set, and even write a debug line when they are called,

It's very difficult to very that you did this correctly without explicit sources. But I can't see any reference to a KeyCallback in the screenshot you provided.

Since 2022-02-07 we added ImGui_ImplGlfw_InstallCallbacks() to facilitate installing callbacks after initialization.

Closing this.

ocornut avatar May 25 '23 14:05 ocornut