Archived

This topic is now archived and is closed to further replies.

sherman

Jim's Book. Core Input Problem.

Recommended Posts

Dear Jim, I am trying to integrate your core input code with my own network code and it seems that creating a non-modal dialog box will prevent the core input from detecting key presses. For example, the following code in Winmain() doesn''t work:
	// Display the LoginDialog
	hWnd_LoginDialog = 	

CreateDialog(hInst,MAKEINTRESOURCE(IDD_LOGINDIALOG),
		hWnd_Application,(DLGPROC)LoginDialogProc);

	
	// Initialize input and input devices
	m_Input.Init(hWnd_Application, hInst);
	m_Keyboard.Create(&m_Input, KEYBOARD);

	// Start the Windows Message Loop
	while(msg.message != WM_QUIT)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		// Get local input every frame 
		m_Keyboard.Acquire(TRUE);  
		m_Keyboard.Read();

		if(m_Keyboard.GetKeyState(KEY_A) == TRUE)
		{
			MessageBox(NULL, "test", "test", MB_OK);
		}
	}
 
However, if I just remove:
// Display the LoginDialog
	hWnd_LoginDialog = 	

CreateDialog(hInst,MAKEINTRESOURCE(IDD_LOGINDIALOG),
		hWnd_Application,(DLGPROC)LoginDialogProc);

 
...it will work perfectly fine. And if I put the core input initialization code before the creation of the login dialog:
// Initialize input and input devices
	m_Input.Init(hWnd_Application, hInst);
	m_Keyboard.Create(&m_Input, KEYBOARD);

// Display the LoginDialog
	hWnd_LoginDialog = 	

CreateDialog(hInst,MAKEINTRESOURCE(IDD_LOGINDIALOG),
		hWnd_Application,(DLGPROC)LoginDialogProc);

 
...it will act weird and keep detecting the keypress although I am not pressing any keys. I am pretty sure it is the creation of the non-modal dialog that is causing the error but is there a way around it if I simply must create that non-modal dialog? Thank you ^_^. _________________ Best regards, Sherman Chin www.Sherman3D.com

Share this post


Link to post
Share on other sites
Ok, it is fixed - apparently I need to change the DirectInput
cooperative level flag in core_input.cpp to DISCL_BACKGROUND.
Now, another problem crops up - DirectInput detects everything
except the arrow keys.

So, for the time being, I have to compromise with the numpad
arrow keys:

if(m_Keyboard.GetKeyState(/*KEY_UP*/ DIK_NUMPAD8) == TRUE)
MoveAction |= 1;
if(m_Keyboard.GetKeyState(/*KEY_DOWN*/ DIK_NUMPAD2) == TRUE)
MoveAction |= 4;
if(m_Keyboard.GetKeyState(/*KEY_LEFT*/ DIK_NUMPAD4) == TRUE)
MoveAction |= 16;
if(m_Keyboard.GetKeyState(/*KEY_RIGHT*/ DIK_NUMPAD6) == TRUE)
MoveAction |= 32;

Anybody knows how I can rectify this problem and get DirectInput
to detect the arrow keys again?

Thanks ^_^

_________________
Best regards,
Sherman Chin
www.Sherman3D.com

Share this post


Link to post
Share on other sites
AP - those are just macros that redefine to DIK_*.

Sherman: I haven''t really tried mixing dialog boxes in that way, but Windows is probably removing all system and related keys (arrows, ALT, etc). You might want to try reading the keyboard before Get/PeekMessage or inside the WM_KEYDOWN function of the dialog box procedure.

Share this post


Link to post
Share on other sites