I'm trying to make an app which reads keys from the keyboard. When I press a key, the program adds it to an array and then I do what I want. I'm not writing in an Edit control. I'm directly pressing buttons on the keyboard, since I want to be able to work with other inputs like readers, that simulate input like keyboards.
Now I added a combo box and radio buttons, with which I'm going to add new stuff in the future. I tried the app again after I added the components and the program doesn't read the keys anymore, since it tries to write inside the combo box. If I press outside of the combo box, or choose an option, nothing happens, and it keeps trying to write in it.
If I press the radio button, the program no longer tries to write in the combo box, but it still doesn't read keys from the keyboard, probably because the focus now is on the radio button.
If I make the combo box property Enabled := false
and I don't press a radio button, then it works again.
I think that the problem is that the program has it's 'focus' on the components. I looked into the properties of the components, and I don't see any property that could help.
Is there a way with code or a property on the components to make the components not take the focus of the program? I work with TRadioButton
, TComboBox
or TAdvComboBox
.
I use the FormKeyDown
event to get the key information.
procedure
TfrmConfigCheck.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
end;
You need to set the KeyPreview
property on the form to True
.
If KeyPreview
is set to False
, then the form's onKeyDown
event isn't called when some components such as a TComboBox
have focus.
But if you set the KeyPreview
property to True
, then the form's onKeyDown
event is called every time a key is pressed down no matter what component is focused on the form.
And regarding your other issue in the comments, you can't set the TComboBox
to be readonly
, but you can set the style
property to csDropDownList
which is kind of a readonly
mode since a user can't enter any detai