Results 1 to 6 of 6

Thread: recognising the f keys???

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    Question recognising the f keys???

    im using ascii codes to recognise when the user presses keys 1-9, how can i recognise when the user presses keys f1 - f12??

    thanks

    GTJ

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: recognising the f keys???

    Those are special function keys and are not sectioned under alphanumeric keys. ASCII values are only assigned to alphanumeric keys.

    You have to use KeyEventArgs.KeyCode or KeyEventArgs.KeyValue to check which key of the keyboard is pressed.
    VB Code:
    1. private void Form1_KeyDown(object sender, KeyEventArgs e)
    2. {
    3.     MessageBox.Show(e.KeyCode.ToString()); 'returns string value of the key pressed
    4.     MessageBox.Show(e.KeyValue.ToString()); 'returns keyboard value of the key
    5. }
    Last edited by Harsh Gupta; Dec 12th, 2006 at 08:39 AM.
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    Re: recognising the f keys???

    so is there anyway i can recognise when the user presses the f keys??

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: recognising the f keys???

    That's what KeyCode or KeyValue meant for!! Under the KeyDown or KeyUp event of your control, use these properties to check which function key is pressed.
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    Re: recognising the f keys???

    yer yer yer, i used your code and no messagebox comes up when i press the f keys!!! (a messagebox does come up for every other key)

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: recognising the f keys???

    Make sure you set the KeyPreview property of the form to True:
    Code:
    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        switch (e.KeyCode)
        {
            case Keys.F1:
                break;
            case Keys.F2:
                break;
            case Keys.F3:
                break;
            case Keys.F4:
                break;
            case Keys.F5:
                break;
            case Keys.F6:
                break;
            case Keys.F7:
                break;
            case Keys.F8:
                break;
            case Keys.F9:
                break;
            case Keys.F10:
                break;
            case Keys.F11:
                break;
            case Keys.F12:
                break;
        }
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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