Jump to content

Win32 How To Tell If Key Pressed When A Child Window Has Focus?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
Using Win32 API, when a child window has the keyboard focus, how can you tell whether a key is pressed (preferably without using functions like GetKeyState())? Is there a WM message that child windows send to the parent window when a key is pressed?

#2
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 763 posts

RhetoricalRuvim said:

Is there a WM message that child windows send to the parent window when a key is pressed?

Not that I am aware of. The focused window must relay the messages to its parent if you want this behavior.

#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
So does it relay the messages by default or is there some setting that I need to set in order for it to do that? And would the child window relay the messages to the parent window by sending some WM message? If so then what is the WM message uMsg value?

#4
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 763 posts
If a message was not dropped (i.e. by setting it's result into something other than zero - indicating that it's been handled) usually the message will be sent to the target parent and continue that way until it hit the top most window. So if the focused window does not handle keyboard messages, then its parent will get the messages. However I don't believe that is your case. In your case I believe the focused window is capable to handle the messages, therefore it will automatically drop the messages.

You can subclass the window procedure of the child window so it will propagate the keyboard messages. Use Window api SetWindowLong if you want to subclass your child window procedure. With it you can change the window procedure address of the child window. Or you can use windows hook method. I have written a short tutorial on windows hook, if you want to choose this path. The tutorial does not directly address this issue, though. But I believe from there you can get some idea for a start.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users