Results 1 to 7 of 7

Thread: handle key press e.g F2

  1. #1

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    handle key press e.g F2

    Just wondering if there is an easy way to handle key presses such as the F keys, i mean when my app doesnt have focus.

    or is it similar to the vb6 method?
    Chris

  2. #2
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: handle key press e.g F2

    I cannot imagine a way to handle KeyPress when you app doesn't have focus. Since the app doesn't have focus, the app itself cannot process them. If you really need to handle this due to having multiple forms that interact with each other, etc. then you would have to go the API route.

    Is the form that will have focus part of your application or another application all together? Is it in the same executable?

  3. #3

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: handle key press e.g F2

    i've done it in vb6 many times, for example, your app is running in the background (system tray), and you hit F2 and it shows up. Just curious if M$ implemented an easy way to have a sub called when F2 is pressed, but I guess the quickest is the old way like vb6
    Chris

  4. #4
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: handle key press e.g F2

    As far as I know using an API is still the only way to handle this. I can't recall which API it is off the top of my head though.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: handle key press e.g F2

    RegisterHotkey

  6. #6

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: handle key press e.g F2

    yea RegisterHotKey was the one i was going to use if there was nothing shorter, thanks
    Chris

  7. #7
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: handle key press e.g F2

    Here is something else you might want to look into:

    http://www.vbaccelerator.com/home/NE...rm/article.asp

    (Download the code at the top left of the page)
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

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