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?
相关问题
- Is there a Delphi 5 component that can handle .png
- Is there a way to install Delphi 2010 on Windows 2
- Is TWebBrowser dependant on IE version?
- iOS objective-c object: When to use release and wh
- DBGrid - How to set an individual background color
相关文章
- Best way to implement MVVM bindings (View <-> V
- Windows EventLog: How fast are operations with it?
- How to force Delphi compiler to display all hints
- Coloring cell background on firemonkey stringgrid
- HelpInsight documentation in Delphi 2007
- Can RTTI interrogate types from project code at de
- What specifically causes EPrivilege to be raised?
- Equivalent to designer guidelines in code
If you want to track alphanumerical keys, then you should use
KeyPress
. Try this: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 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
OnKeyDown
event handler, is to check ifssShift in Shift
, whereShift
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
using the xor operator.)