Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:53:02+00:00 2026-06-07T08:53:02+00:00

To keep myself interested, I try to put little Easter Eggs in my projects

  • 0

To keep myself interested, I try to put little Easter Eggs in my projects (mostly to amuse myself). I’ve seen some websites where you can type a series of letters “aswzaswz” and you get a “secret function” – how would I achieve this in C#?

I’ve assigned a “secret function” in the past by using modifier keys

        bool showFunThing = (Control.ModifierKeys & Keys.Control) == Keys.Control;

but wanted to get a bit more secretive (without the modifier keys) I just wanted the form to detect a certain word typed without any input … I’ve built a method that I think should do it:

    private StringBuilder _pressedKeys = new StringBuilder();

    protected override void OnKeyDown(KeyEventArgs e)
    {
        const string kWord = "fun";
        char letter = (char)e.KeyValue;
        if (!char.IsLetterOrDigit(letter))
        { return; }
        _pressedKeys.Append(letter);
        if (_pressedKeys.Length == kWord.Length)
        {
            if (_pressedKeys.ToString().ToLower() == kWord)
            {
                MessageBox.Show("Fun");
                _pressedKeys.Clear();
            }
        }
        base.OnKeyDown(e);
    }

Now I need to wire it up but I can’t figure out how I’m supposed to raise the event in the form designer … I’ve tried this:

    this.KeyDown +=new System.Windows.Forms.KeyEventHandler(OnKeyDown);

and a couple of variations on this but I’m missing something because it won’t fire (or compile). It tells me that the OnKeyDown method is expecting a certain signature but I’ve got other methods like this where I haven’t specified arguments.

I fear that I may have got myself confused so I am turning to SO for help … anyone?

EDIT: The ProcessCmdKey seems to be the way that works with the following:

    private StringBuilder _pressedKeys = new StringBuilder();
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        const string kWord = "fun";
        char letter = (char)keyData;
        if (!char.IsLetterOrDigit(letter))
        {return true;}
        _pressedKeys.Append(letter);
        if (_pressedKeys.Length == kWord.Length)
        {
         if (_pressedKeys.ToString().ToLower() == kWord)
            {
                MessageBox.Show("Fun");
                _pressedKeys.Clear();
            }
            _pressedKeys.Clear();
        }
     return true;
    }

Thanks all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:53:04+00:00Added an answer on June 7, 2026 at 8:53 am

    Try this:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == (Keys.P|Keys.Control))
        {
            //do my prank
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
    

    This will fire when you press CTRL + P.

    refer: ProcessCmdKey

    This method is called during message preprocessing to handle command
    keys. Command keys are keys that always take precedence over regular
    input keys. Examples of command keys include accelerators and menu
    shortcuts. The method must return true to indicate that it has
    processed the command key

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some NSLog calls that I do to keep myself from flying blind
I keep saying to myself there must be a better way but I can't
So, I decided to look back at some data structures to keep myself sharp
So, I'm developing some software, and trying to keep myself using TDD and other
I got this project going on for myself to keep some thing in order.
As a hobby project to keep myself out of trouble, I'd like to build
So this is more of a generic question. I seem to keep finding myself
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
I keep getting this Magento error emailed to myself: URL: http://mysite.com/sendfriend/product/send/id/1/ IP Address: 66.249.65.69
I've had some trouble finding information about Apple's policies regarding in-app ads. I'm interested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.