Results 1 to 3 of 3

Thread: [RESOLVED] Capture Multiple Key Presses

Threaded View

  1. #3

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Capture Multiple Key Presses

    That worked perfectly. I figured it would be something along those lines but I couldn't get it right. Looks like my more complex solution was at fault. Oh well.

    Thanks!

    Edit: If anyone is interested here is the code I used. it's a slightly modified version of the one above and should give more customizability.

    csharp Code:
    1. private Dictionary<int, char> secret_code = new Dictionary<int, char>()
    2. {
    3.   {0, 't'},
    4.   {1, 'e'},
    5.   {2, 's'},
    6.   {3, 't'}
    7. };
    8.  
    9. private void frmMain_KeyPress(object sender, KeyPressEventArgs e)
    10. {
    11.   if (e.KeyChar == secret_code[key_presses])
    12.   {
    13.     if (key_presses == (secret_code.Count() - 1))
    14.     {
    15.       this.key_presses = 0;
    16.       MessageBox.Show("You sound the secret!", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
    17.     }
    18.     else
    19.     {
    20.       ++this.key_presses;
    21.     }
    22.   }
    23.   else
    24.   {
    25.     this.key_presses = 0;
    26.   }
    27. }
    Last edited by sciguyryan; Jan 12th, 2010 at 02:57 PM. Reason: Added code.
    My Blog.

    Ryan Jones.

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