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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:10:27+00:00 2026-05-16T04:10:27+00:00

I am working with Delphi. I want to track on which key is pressed.

  • 0

I am working with Delphi. I want to track on which key is pressed. I am using KeyDown event of TForm. It is working fine but the problem is that, if I press and lower case letter, though it gives me upper case of that letter. How can I recognize the key pressed is lower case or upper case?

  • 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-16T04:10:28+00:00Added an answer on May 16, 2026 at 4:10 am

    If you want to track alphanumerical keys, then you should use KeyPress. Try this:

    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      ShowMessage(Key);
    end;
    

    The problem with KeyDown is that is responds to a key being depressed, and surely enough, if you want to enter either “K” or “k” on the keyboard, you press the same button, right? So if you want to stick to KeyDown, then you need to check separately if the Caps Lock key is on, or if the Shift key is depressed. To test if a toggle key (such as Caps Lock) is on, or if a regular key is depressed, you can use

    function IsKeyDown(const VK: integer): boolean;
    begin
      IsKeyDown := GetKeyState(VK) and $8000 <> 0;
    end;
    
    function IsKeyOn(const VK: Integer): boolean;
    begin
      IsKeyOn := GetKeyState(VK) and 1 = 1;
    end;
    

    To check if the Caps Lock key is on, use IsKeyOn(VK_CAPITAL). To check if the shift key is depressed, use IsKeyDown(VK_SHIFT).

    An alternative way of checking if the shift key is depressed, which only works in the OnKeyDown event handler, is to check if ssShift in Shift, where Shift is a parameter of that event handler function.

    (By the way, because the action of Caps Lock being on is counteracted by the Shift key (that is, if you press Shift+A when Caps Lock is on, a small “a” is inserted), the check to employ when testing for capitals is

    IsKeyOn(VK_CAPITAL) xor IsKeyDown(VK_SHIFT)
    

    using the xor operator.)

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

Sidebar

Related Questions

I have a simple Delphi program that I'm working on, in which I am
Simple problem. I'm working on a Delphi 2007/WIN32 application which now uses MS Access
I'm working in Delphi 2007. Net, where I can find an example of using
Working on a service application in Delphi 5 that is intended to run on
i am working on a custom component in Delphi -7 for which i have
Version used: Delphi 7. I'm working on a program that does a simple for
im working on delphi 7 and i want to how to copy/assign the content
I m working with Delphi 7 and I want to find out the path
I am working with delphi, I want a list of all files of a
I am working with delphi. After I got a solution of this problem, Now

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.