Form OnKeyPress vs OnKeyUp lazarus / 31-LCL ---------------------------------------------------------------------- Frank · 2015-01-21 21:18 Hi. Lazarus-1.2.6 w/fpc-2.6.4 on Slackware64 14.1 I have discovered odd behavior, OnKeyPress of Form, pressing key "k" give "k" (ord 107) as Key. But OnKeyDown/OnKeyUp Char(Key) gives "K" (75). If it matters, KeyPreview is true. Any ideas? Am I missing something ? Is this to be expected ? Thanks (in advance). ---------------------------------------------------------------------- Blaazen · 2015-01-21 21:34 I can confirm that. I did a quick test and Delphi7 does the same. In OnKeyUp, you have parameter ShiftState, where you can detect whether it is 'k' or 'K'. In your test program, when you switch CapsLock on, both events give 75. ---------------------------------------------------------------------- jwdietrich · 2015-01-21 21:44 The reason for this at a first glance unintuitive behaviour is that OnKeyPress delivers an ASCII representation of your entry (therefore it doesn't report e.g. pressing of function keys), while OnKeyUp (and OnKeyDown) provide the lowest level of keyboard response. Therefore they respond to all keyboard events. See http://delphi.about.com/od/objectpascalide/a/keyboard_events.htm for details. ---------------------------------------------------------------------- Frank · 2015-01-21 21:54 @ Blaazen, @jwdietrich Thanks ! @jwdietrich, I will use the web page to adjust my approach. Mind you I don't remember this happening with controls (non-forms), but I could be mistaken... Anyway thank you ! Frank