Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By jmcilhinney

Thread: Accesing a Fn Keys

  1. #1
    vicdeveloper is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2016
    Posts
    11
    Reputation
    13

    Question Accesing a Fn Keys

    Hello,

    I want to know how can I make an option to use F1 or Fn keys when my form loads.

    I guess that it need to be related with KeyDown or KeyPress Events, but, I dont know how to do it.

    The things that I want to do with this is, call a form or function when Fn key is pressed.

    See ya,

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,814
    Reputation
    1707
    When you say Fn, do you just mean any standard function key, i.e. F1 - F12, or do you mean the hardware Fn key that many keyboards use to provide multiple functions from a single key?

    If it's the latter then you should forget about it. That key is basically for the hardware only. It will behave differently on different keyboards and won't even be present on some. Using it for anything other than what the manufacturer intended is rarely, if ever, justified.

    If it's the former then you should also forget. The standard functionality for the F1 in Windows is for Help. Using it for any other purpose is back practice. You should use some other key or key combination, e.g. F2 or Ctrl+Shift+Q. In that case you would indeed handle the appropriate KeyDown event. If you want to react to a key or key combination regardless of which control has focus then you should handle the KeyDown event of the form, but make sure you set the KeyPreview property to True.

  3. #3
    vicdeveloper is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2016
    Posts
    11
    Reputation
    13
    Hello dude,

    I have and found the solution.

    It need to be added this code in the KeyDown event and the KeyPreview is needed to set True.

    If e.KeyCode = Keys.F3 Then
    MsgBox("You pressed F3 Key. ")
    End If
    See ya,
    Last edited by vicdeveloper; 09-16-2016 at 11:33 AM. Reason: Response content edited.

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,814
    Reputation
    1707
    Quote Originally Posted by vicdeveloper View Post
    Hello dude,

    I have and found the solution.

    It need to be added this code in the KeyDown event and the KeyPreview is needed to set True.



    See ya,
    Just be aware that that code will react to F3, Ctrl+F3, Shift+F3, Alt+F3, Ctrl+Shift+F3, etc. That's because KeyCode only cares about the last key that was depressed and not any modifier keys that are already depressed. If you want to react to F3 alone then you should use KeyData rather than KeyCode. KeyData includes the last key to be depressed and current modifiers, so testing for F3 will only detect F3 alone.
    vicdeveloper likes this.

  5. #5
    vicdeveloper is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2016
    Posts
    11
    Reputation
    13
    Thanks for your response dude. Everything is working Ok with KeyData instead KeyCode.

    See ya,

Tags for this Thread

Bookmarks

Posting Permissions

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