CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Jul 2010
    Posts
    1

    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.

  2. #2
    Join Date
    Dec 2009
    Posts
    596

    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.

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Dec 2009
    Posts
    596

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Feb 2011
    Posts
    4

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    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....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  9. #9
    Join Date
    Feb 2011
    Posts
    4

    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Feb 2011
    Posts
    4

    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.

  12. #12
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Thumbs down 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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  13. #13
    Join Date
    Feb 2011
    Posts
    4

    Re: how to capture keypress event when window is not focused

    Quote Originally Posted by dglienna View Post
    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.

  14. #14
    Join Date
    Jan 2002
    Posts
    195

    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++.

  15. #15
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.
    Always use [code][/code] tags when posting code.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured