I have a TListView
(it is focused all the time) and an OnKeyDown
event handler on my Form (its KeyPreview
property is true).
playlist
is my TListView
component (Style = vsReport
).
void __fastcall Tmform::mformKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if(Shift.Contains(ssCtrl)) // hotkeys with CTRL
{
switch(Key)
{
case vkF: findDoublesbtnClick(mform); break; // [FIND TWINS]
case vkD: dbsClick(mform); break; // [DELETE BAD SONGS]
case vkA: playlist->SelectAll(); break; // [CTRL + A]
case vkS: settingsClick(mform); break; // [SETTINGS]
}
}
else // just keys
{
switch(Key)
{
case vkReturn: if(playlist->SelCount) pl.refreshSong(); break; // [ENTER]
case vkDelete: af.deleteFiles(); break; // [DELETE]
case vkSpace:
case vkNumpad3: pl.playPauseResume(); break;
case vkSubtract: prevbtnClick(mform); break; // [PREVIOUS]
case vkAdd: nextbtnClick(mform); break; // [NEXT]
case vkC: counterClick(mform); break; // [LISTENINGS WIN]
}
}
Why does it beep when I press any key (with the TListView
focused)?
So, I found out, why it beeps. It seems to be standard behavior of TListView component. When one item in TListView is selected (and TListView has focus), any character input triggers "select the typed item" method, that trying to find and select item by our input.
That was the answer I was interested about. To make work hot keys (including one-key) I used next code:
It works with all existing PC keyboard layouts. But with 'alt' and 'win' keys still beeps, because any key with 'alt' or 'win' does not triger the ListViewKeyPress event.
Thank for your help!