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 7002943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:59:44+00:00 2026-05-27T20:59:44+00:00

I want to capture when the ALT key has been pressed even if my

  • 0

I want to capture when the ALT key has been pressed even if my control hasn’t the focus.

Is there something similar to this in System.Windows.Forms.Control?

public void OnModifierKeyPressed(KeyEventArgs e);

Or maybe processing any WndProc message?

Thanks in advance.


EDIT:

I need to capture when the user pressed the ALT key to paint the key accelerator underline in my control (as a button does). I’m sure that the following messages are sent to the control when the user press ALT and the control doesn’t have the focus:

WndProcMessage as integer:
296
8235
15
133
20

EDIT2:


Finally, I found the message that is involved, here:

Msg:    WM_UPDATEUISTATE                        0x0128
WParam: UISF_HIDEACCEL                          0x2

But, as Cody Gray said, this is not needed, you can use Control.ShowKeyboardCues property.

  • 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-05-27T20:59:45+00:00Added an answer on May 27, 2026 at 8:59 pm

    Only the control with the focus will receive keyboard events. So there is no method to override or event to handle on your custom control that will allow you to detect key presses when your custom control does not currently have the focus.

    At any rate, the new information added to your question indicates that this is irrelevant. If all you want to do is draw the keyboard accelerators at the appropriate time, there’s a much simpler solution.

    In the Paint event handler for your custom control (where you draw the control’s text), you should check the value of the Control.ShowKeyboardCues property. If the value is true, then you should make keyboard accelerators visible; otherwise, you should omit drawing them.

    Similarly, you should also be checking the value of the Control.ShowFocusCues property. That tells you whether to draw the focus rectangle around the control.
    Use the ControlPaint.DrawFocusRectangle method to draw said focus rectangle.

    Something like:
    (I don’t have a .NET compiler in front of me, so the code might have errors…)

    // Draw the text
    using (StringFormat sf = new StringFormat())
    {
        sf.Alignment = StringAlignment.Center;
        sf.LineAlignment = StringAlignment.Center;
        sf.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotKeyPrefix.Hide;
    
        if (this.Enabled)
        {
            using (Brush br = new SolidBrush(this.ForeColor))
            {
                g.DrawString(this.Text, this.Font, br, this.ClientRectangle, sf);
            }
        }
        else
        {
            SizeF sz = g.MeasureString(this.Text, this.Font, Point.Empty, sf);
            RectangleF rc = new RectangleF(Point.Empty, sz);
            ControlPaint.DrawStringDisabled(g, this.Text, this.Font, this.BackColor, rc, sf);
        }
     }
    
     // Draw the focus rectangle
     if (this.ShowFocusCues && this.ContainsFocus)
     {
         ControlPaint.DrawFocusRectangle(g, this.ClientRectangle);         
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to capture something similar to the following IWebElement commentField = Regex.Match(driver.PageSource,TextBoxComments$,RegexOptions.RightToLeft); Where
I want to capture a Flick touch event in Update method. In there, I
I want to capture keystrokes when the focus in on a panel in java.
i want to capture all tags named 'STRONG' i can use <STRONG.*?</STRONG> this is
I want to capture an image of the screen, however there are some wpf
I want to capture output from a C program I'm launching like this: p
I want capture Rank from this code : $RankStr = 'var trafficstatsSnippet = /site/trafficstats;pysa1bpbPOVl6Wm5d4Zv4nKXKdM%3D
I want capture the Home key, but I have call setType(WindowManager.LayoutParam.TYPE_KEYGUARD) in onAttachedToWindow ,
I want to capture video from my activity This is my source code mTempVideoPath
I want to capture the Ctrl + C ( SIGINT ) signal sent from

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.