F10 key not detected.

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
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

F10 key not detected.

Post by arras »

F10 key seems not to be detected on my computer for some reason. All other F keys are so it may be bug. I ma using Irrlicht 1.4 and DevC++.
Small test:

Code: Select all

#include <irrlicht.h>
using namespace irr;

gui::IGUIStaticText *Text1;
gui::IGUIStaticText *Text2;

class EventReceiver : public IEventReceiver
{
public:
   virtual bool OnEvent(const SEvent& event)
   {
      if (event.EventType == EET_KEY_INPUT_EVENT)
      {
         if(event.KeyInput.PressedDown)
         {
            if(event.KeyInput.Key == KEY_F10)
            {
               Text1->setText(L"KEY F10 was pressed!");
               return true;
            }
            
            if(event.KeyInput.Key == KEY_F9)
            {
               Text2->setText(L"KEY F9 was pressed!");
               return true;
            }
         }
         else
         {
            if(event.KeyInput.Key == KEY_F10)
            {
               Text1->setText(L"KEY F10 was left up!");
               return true;
            }
            
            if(event.KeyInput.Key == KEY_F9)
            {
               Text2->setText(L"KEY F9 was left up!");
               return true;
            }
         }
      }
      
      return false;
   }
};

int main()
{
   EventReceiver receiver;
   
   IrrlichtDevice* device = createDevice(
      video::EDT_SOFTWARE,
      core::dimension2d<s32>(640, 480), 32, false, false, false, &receiver);
    
   video::IVideoDriver* driver = device->getVideoDriver();
	gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
	
	guienv->addStaticText(L"Press F9 or F10 key!", core::rect<s32>(40,40,200,50));
	Text1 = guienv->addStaticText(L"KEY F10 was not pressed yet.", core::rect<s32>(40,80,200,90));
	Text2 = guienv->addStaticText(L"KEY F9 was not pressed yet.", core::rect<s32>(40,60,200,70));

	while(device->run())
   {
      driver->beginScene(true, true, video::SColor(255,255,255,255));
		guienv->drawAll();
		driver->endScene();
   }
   device->drop();

   return 0;
}
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

How about a quick search for F10? This has been covered at least twice.

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=23410
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=22630
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Third time lucky :D
OK just remove post if you see it fit.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

vitek wrote:How about a quick search for F10? This has been covered at least twice.

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=23410
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=22630
Neither of those threads show the proper solution. Look into LowLevelKeyboardProc
Image
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

LowLevelKeyboardProc Function

The LowLevelKeyboardProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function every time a new keyboard input event is about to be posted into a thread input queue. The keyboard input can come from the local keyboard driver or from calls to the keybd_event function. If the input comes from a call to keybd_event, the input was "injected". However, the WH_KEYBOARD_LL hook is not injected into another process. Instead, the context switches back to the process that installed the hook and it is called in its original context. Then the context switches back to the application that generated the event.
That would require some Windows programing skill and/or modification in to Irrlicht cource I guess...
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

From 3Demon (note this also adds supprot for the left and right windows keys, and the windows key are only over-ridden if in Full-Screen Mode ).

Code: Select all

HHOOK LowLevelKeyboardHook;

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{
	if( nCode < 0 || nCode != HC_ACTION )  // do not process message 
		return CallNextHookEx( LowLevelKeyboardHook, nCode, wParam, lParam );

	HWND window = GetActiveWindow();
	demon::CDemonDeviceWin32* dev = getDeviceFromHWnd( window );
	if( dev )
	{
		demon::SEvent event;
		event.EventType = demon::EET_KEY_INPUT_EVENT;
		BYTE allKeys[256];
		WORD KeyAsc=0;
		GetKeyboardState(allKeys);
		ToAscii(wParam,lParam,allKeys,&KeyAsc,0);

		event.KeyInput.Shift = ((allKeys[VK_SHIFT] & 0x80)!=0);
		event.KeyInput.Control = ((allKeys[VK_CONTROL] & 0x80)!=0);
		event.KeyInput.Char = KeyAsc; //KeyAsc >= 0 ? KeyAsc : 0;

		KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*)lParam;
		switch( wParam ) 
		{
			case WM_KEYDOWN:
			{
				event.KeyInput.PressedDown = true;

				if( g_windowActive )
				{
					if( g_fullScreen && p->vkCode == VK_LWIN )
					{
						event.KeyInput.Key = demon::KEY_LWIN;
						dev->postEventFromUser( event );
						return 1;
					}
					else if( g_fullScreen && p->vkCode == VK_RWIN )
					{
						event.KeyInput.Key = demon::KEY_RWIN;
						dev->postEventFromUser( event );
						return 1;
					}
					else if( p->vkCode == VK_F10 )
					{
						event.KeyInput.Key = demon::KEY_F10;
						dev->postEventFromUser( event );
						return 1;
					}
				}
				break;
			}
			case WM_KEYUP:
			{
				event.KeyInput.PressedDown = false;
			
				if( g_windowActive )
				{
					if( g_fullScreen && p->vkCode == VK_LWIN )
					{
						event.KeyInput.Key = demon::KEY_LWIN;
						dev->postEventFromUser( event );
						return 1;
					}
					else if( g_fullScreen && p->vkCode == VK_RWIN )
					{
						event.KeyInput.Key = demon::KEY_RWIN;
						dev->postEventFromUser( event );
						return 1;
					}
					else if( p->vkCode == VK_F10 )
					{
						event.KeyInput.Key = demon::KEY_F10;
						dev->postEventFromUser( event );
						return 1;
					}
				}
				break;
			}
		}
	}

	return CallNextHookEx( LowLevelKeyboardHook, nCode, wParam, lParam );
}
Image
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Spintz, thanks for going over the feud and trying to help. That was kind spirited of you.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Dorth wrote:Spintz, thanks for going over the feud and trying to help. That was kind spirited of you.
No problem. Am I normally mean?
Image
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Am I normally mean?
I can witness you are not!
And thanks for that hosting space again :wink:
Post Reply