CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Location
    Israel
    Posts
    140

    How to catch a keyboard key?

    I have an explorer style application (with 2 user controls - tree and list, toolbar etc..)
    I need to know when the user presses the "Ctrl" key in any place in the application.
    What is the way to do it?
    Thanks Sigal


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How to catch a keyboard key?

    set the Keypreview property of the form to true and trap all keypress, keydown, keyup event at the Form_Keypress event handler level


  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: How to catch a keyboard key?

    sample:

    private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
    If Shift And vbKeyControl = vbKeyControl then
    MsgBox "control pressed"
    End If
    End Sub





  4. #4
    Join Date
    Jul 1999
    Location
    Israel
    Posts
    140

    Re: How to catch a keyboard key?

    Thanks but i have more then two forms and i don't want to define the Form_KeyDown routine in every form
    I want that the main form will catch the key of its child forms.


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: How to catch a keyboard key?

    check out http://www.vbaccelerator.com/codelib...mr/hotkeyr.htm
    It deals with registering application wide hotkeys.


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