how to capture keypress event when window is not focused
i am trying my hand in visual basic 2010
it's a windows form program, what am i trying to do is,
when i press ctrl+v (yes pasting) in other program, whether it be notepad or a text box, something also happens in my program.
So i need to capture the keypress event when my form does not have the focus. I have been trying but no success in 2 days.
I would hate to create a windows service for this, but if there is no other way i might have to do it.
Re: how to capture keypress event when window is not focused
I haven't worked with vb2010 yet so I don't know if this will help. I'm not even sure if this will work on 2008 because I might have the condition interpretted incorrectly. But is the form's Keypreview property set to true? If not; see if setting it to true solves the problem.
Re: how to capture keypress event when window is not focused
Key preview will not help here. The poster is asking to capture key strokes while his/her program is not focused. This is the basis for creating a key logger.
Re: how to capture keypress event when window is not focused
Good to know DataMiser. I'll add keylogger on my todo list of stuff to get aquainted with along with winsock and web services.
Re: how to capture keypress event when window is not focused
Discussing that can get you banned. Read the AUP at the bottom of every page
Re: how to capture keypress event when window is not focused
I actually have the same question he does. I am not attempting to make a keylogger. my goal is to have my program react to keypress' while in a game.
the program im writing will react to the user pressing a key twice. each time it will log the coords of the mouse pointer. after the second keypress it will screenshot the area within the coords and then it analyzes the data in the picture.
Re: how to capture keypress event when window is not focused
If it has to trap the first click, and everything in between, even though it *might* not save the keystrokes, adding one line of code would change any code that we did post originally. Someone would misuse it.
Re: how to capture keypress event when window is not focused
This topic has come up several times and unfortunately .. the only diference between the code for this and a keylogger, is that the keylogger stores and relays all keypresses to a 3rd party .. (which is also discussed here in detail) ...
Unfortunately as innocent as your app would be, any other Malicious 'Hacker' could use the same code to steal info....
Best bet is re-evaluate your proggy, and rather try something else....
Re: how to capture keypress event when window is not focused
Well I don't know how else to do this. I am just trying to make custom trainer for a game. Is there any other way for.the player to trigger a background app while playing the game?
I don't mind trying to move the discussions to private. I truly have no ill intent for this program.
Re: how to capture keypress event when window is not focused
Ask the creator for an API, if that's what they intend for their app. Probably not allowed, though.
Re: how to capture keypress event when window is not focused
I found my solution. Global hotkeys is what I need. It will let me register a specific key to activate a routine in my program even if another program is active. Maybe this will help others that had the same problem as me.
Re: how to capture keypress event when window is not focused
Why would you post that for eternity? Hope the moderators go easy on you, but we tried to warn you.
Re: how to capture keypress event when window is not focused
Quote:
Originally Posted by
dglienna
Why would you post that for eternity? Hope the moderators go easy on you, but we tried to warn you.
Go easy on me for what? i found this solution in this forum. plus its easy to find by googling hotkeys and VB. its everywhere.
if its because this could be used in a malicious way then they should just ban the whole forum. just about every topic can be twisted in an evil way. they need to remove all posts that deal with editing files, downloading files, communicating over a network. pretty much everything.
Re: how to capture keypress event when window is not focused
While a key logger may be a questionable application I can think of hundreds of uses for the need to capture the key board and it is a basic opperation in a video game. This is however event driven programming which is how WIN32 progamming works. I would requimend you study using events with VB if you want to go more indept with this. You will find that VB.NET has become almost as powerful as C++.
Re: how to capture keypress event when window is not focused
Of course there are many cases where you need to capture a key press but very few where you would need to do so while another application has the focus. I can't think of any application for this that would not be suspect.
Re: how to capture keypress event when window is not focused
People try to hack many things.
Re: how to capture keypress event when window is not focused
I can give you an example of an application that would need to capture the key_Down and key_Up events that is perfectly legitament. Say I wanted to be able to make any window a top most window using a hot key. FN+T for instance. The only way to do this would be to capture the Keypress event which would of course also give me the handle to the window that currently has focus. I could then set that window to a TopMost window. This would be a perfectly legit use of capturing the keypress event and would not have a window of its own. In fact it would also be extreamly handy.
Re: how to capture keypress event when window is not focused
Closed, just in case this gets out of hand