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?
Share
If you want to track alphanumerical keys, then you should use
KeyPress. Try this:The problem with
KeyDownis 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 toKeyDown, 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 useTo check if the Caps Lock key is on, use
IsKeyOn(VK_CAPITAL). To check if the shift key is depressed, useIsKeyDown(VK_SHIFT).An alternative way of checking if the shift key is depressed, which only works in the
OnKeyDownevent handler, is to check ifssShift in Shift, whereShiftis 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
using the xor operator.)