Solved

Keyboard Hooking (adding a few of my own)

Posted on 2004-04-27
15
202 Views
Last Modified: 2010-04-01
Is it possible to rewrite the keyboard callback so that I can add my own keyboard messages? The problem I am faced with is as follows: I need to send keystrokes to another window (non-active). Every piece of code I have come across needs the window to be active...perhaps I can get around this by installing a callback. How exactly do I send keystrokes (say, the letter "n") to an app?

I've figured I'll use SendMessage with a user-defined lparam to active the code, hWnd for the window, and...
0
Comment
Question by:rossryan
15 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 10936424
could you re-route through a file?

IE: send everything to a file and then Sendmessage from that?

Just a thought, I'm not really sure though.
0
 
LVL 7

Expert Comment

by:vijay_visana
ID: 10938138
0
 
LVL 8

Expert Comment

by:_corey_
ID: 10940333
I don't see why you couldn't catch teh WM_KEYUP messages in your default window proc/event handler.  I'm not sure you'll need a custom keyboard hook because your control will be active, right? And you just don't want the target window to have to be active.  Am I wrong?

Then send commands via PostMessage or SendMessage.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:rossryan
ID: 10942346
Aright...here's the scenario: I have a large OpenGL window. That completely covers the desktop.

I have code from Feng Yuan [MSFT] which allows me to hook into the windows, on that desktop.

So even when the windows are completely covered by my large window, I can get a snapshot of them. And create texture equivalents inside OpenGL.

These windows do not have focus. They are not active. They cannot be active or have focus.

These windows are regular windows such as "Word" or "Notepad". They are not controls.

I need only the code to send a keyboard command to one of those windows. The general idea is that when someone selects the "Notepad" texture in the OpenGL window, all keyboard output will be redirected to the "Notepad" window. I am interested in only the redirection part, I already know how to get keyboard output from inside OpenGL.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 10944692
You have to give a window the focus, and then initiate a callback like:

//notepad has focus.

GlutKeybFunc(Windows_Callback_forNotepad());


Just make sure you re-initialize GlutKeybFunc to your own handler after you are done with notepad or said application.

0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 10944697
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 10944698
Oh, wait.  LOL.  That didn't work for you?
0
 

Author Comment

by:rossryan
ID: 10945565
;) True enough. What I am trying to accomplish ranks up there in difficulty.

Why can't I push my own keyboard messages through the keyboard callback? I do know the syntax, or if it is possible.


Keep this in mind.->These windows do not have focus. They are not active. They cannot be active or have focus.

Goto http://workspaces.gotdotnet.com/4DDesktop. Download the latest screenshot (under releases), and you may understand what I have to contend with...
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 10952648
Why can't they have focus like a normal OS?

What if you used a sendmessage function to send it that way?  

The only other think I could think of would be overwriting the buffer to add in what you want.
0
 

Author Comment

by:rossryan
ID: 10965089
Becuase 1.) It runs on Windows. 2.) The texture window is not the real window.

Window's creates the real window, and my program copies the image of that window into OpenGL. If the real window has focus, then my program does not...
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 10981853
try send message(hwnd, wm_char, ascii char of letter, 20003);




0
 

Author Comment

by:rossryan
ID: 11020242
Interesting. No dice though. Characters simply do not show up.
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11293886
PAQed, with points refunded (500)

Netminder
EE Admin
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question