Multiple Window Keyboard Association?

Started by
6 comments, last by Roof Top Pew Wee 22 years, 5 months ago
I am writing a program which has multiple windows, each with their own handles (G.hWnd, G.hWnd2, G.hWnd3, and so on). Well, I would like to have all the windows be able to recieve input from the keyboard. However, to set up the keyboard with DirectInput, you have to do the following: G.lpDIKeyboard->SetCooperativeLevel(G.hWnd3, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); The first argument is a handle to a window, and I have only been able to get the keyboard to work with that specific window. Is there anyway to pass multiple handles to this function, or does anyone know of another method to do this, such as calling a function that lets you add windows to the object? If this is not possible, is the only way to get multiple windows to recognize the keyboard by creating multiple directInput objects? Thanks for any help. --Vic--
Advertisement
this isn''t EXACTLY an answer to your problem, but:
you could put code in your program so that whenever you get keyboard input with the one window, it passes it on (if relevant) to the other ones.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Krez:

Oops, I must not have stated this specifically, but as in the case I stated above, where I pass G.hWnd3 as the first argument to the SetCooperativeLevel function, the only time the keyboard is read is when whatever window G.hWnd3 is a handle to is activated. So if say I have G.hWnd, G.hWnd2, and G.hWnd3 on the screen, if I click on the window represented by G.hWnd2, then input is no longer read. That way, your suggestion won''t work. Any other ideas anyone?

--Vic--
ah my bad...
i shoulda read it better...

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
You can make DI process input events even if the window it is attached to is in the background. Use the DISCL_BACKGROUND flag in your call to SetCooperativeLevel instead of DISCL_FOREGROUND (background here means "foreground *and* background").

I know this doesn''t exactly answer your question, but you could use krez'' method if you set your cooperative level like this.
How about making an invisible window (i.e. never shown) to be in the input focus window, then make all the rest of your (visible) windows child windows with the focus window as their parent.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

When it comes to stuff that''s not direct to the game (EG. graphics) I try to get by with as little learning as possible. I don''t know how to do child windows, nor do I want to redo my whole program, so I think I''ll stick to doing the Foreground/background thing. This should fix it.
Thanks

--Vic--
Heh, it reads: Multiple Window Keyboard Ass

This topic is closed to new replies.

Advertisement