Solved

Keyboard Hooking (adding a few of my own)

Posted on 2004-04-27
15
201 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting to C# also VS2015 5 128
How to copy an image file into clipboard C/C++? 1 170
Unable to start eclipse ? 17 141
c++ reading data from file into two dimensional array 3 109
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 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