Events for LMENU and RMENU

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Events for LMENU and RMENU

Post by Acki »

hi,
while I was working on a virtual keyboard I dicovered problems with the Alt keys (LMENU and RMENU) !!! :shock:
if you press the left Alt key it stays pressed until you press it again !!!
if you press the right Alt key also the left Ctrl key gets pressed !!!

this code shows the three keys and it's states:

Code: Select all

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;

class MyEventReceiver : public IEventReceiver{
  public:
    virtual bool OnEvent(const SEvent& event){
      if(event.EventType == irr::EET_KEY_INPUT_EVENT)
        KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
      return false;
    }
    virtual bool IsKeyDown(EKEY_CODE keyCode) const{
      return KeyIsDown[keyCode];
    }
    MyEventReceiver(){
      for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
        KeyIsDown[i] = false;
    }
  private:
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};

int main(){
  MyEventReceiver receiver;
	IrrlichtDevice* device = createDevice(EDT_DIRECT3D9, dimension2du(640, 480), 16, false, false, false, &receiver);
	IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

  IGUIFont* fnt = guienv->getBuiltInFont();
  SColor col;

	while(device->run()){
		driver->beginScene(true, true, video::SColor(0,50,100,150));

    col = receiver.IsKeyDown(KEY_LCONTROL)? SColor(255,0,255,0):SColor(255,0,0,0);
    fnt->draw(L"LCONTROL", recti(50,100,100,110), col);

    col = receiver.IsKeyDown(KEY_LMENU)? SColor(255,0,255,0):SColor(255,0,0,0);
    fnt->draw(L"LMENU", recti(120,100,150,110), col);

    col = receiver.IsKeyDown(KEY_RMENU)? SColor(255,0,255,0):SColor(255,0,0,0);
    fnt->draw(L"RMENU", recti(170,100,200,110), col);

		driver->endScene();
	}
	device->drop();
	return 0;
}
I hope you can confirm and fix it !!! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Speaking of which, have you tried KEY_SNAPSHOT? I am furiously pressing my "print screen" key and not getting a result.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

@agamemnus: The key-down event for the snapshot key isn't passed from the system, so not even Irrlicht receives it. My guess is that it's a system-key which you usually don't use in applications. But as workaround you can get it's current state with GetAsyncKeyState. Or use the key-up event, I think you receive that. Got discussed already in the past, so for that problem please continue discussion here in case you find out more stuff: http://irrlicht.sourceforge.net/phpBB2/ ... eysnapshot


@Acki: Thx, I'll love it when I get a real testcase :-) I hope I find some time in the evening to test it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

agamemnus wrote:have you tried KEY_SNAPSHOT? I am furiously pressing my "print screen" key and not getting a result.
yes, that's right...
but I thought it's because of what CuteAlien said... ;)

there also is a problem with the F10 key, IIRC already discussed in the forums...

also the Return and Enter keys are using the same key code (KEY_RETURN = 13), what I don't like !!!
different keys should have different key codes... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Acki wrote: also the Return and Enter keys are using the same key code (KEY_RETURN = 13), what I don't like !!!
different keys should have different key codes... ;)
Yeah, I know also about that already. They have the same key-code, so that is fine. But there should be an additional flag to be able to distinguish them (Windows passes that in the lparam or wparam). But there's more information passed like that and when adding one flag I might as well look into the other information which we drop so far. And then I have to make it work the same on Linux. So that is a little more work.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I can reproduce it and don't know why it hasn't been noticed before. But unfortunately also no idea how to fix this. AltGr generates two WM_KEYDOWN messages - one for left-control and one for right-alt. And it seems wParam and lParam both have the same bitset as in the usual LCONTROL event. Maybe there are tricks with GetKeyboardState and figuring out previous state etc... if anyone has an idea I would be glad. Preferably one that won't break the other exception cases.

Maybe it's something which can't be done with WM_KEYDOWN and we will have to go down to MessageHooks to be able to handle this.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply