I want to implement the keyboard shortcuts in Delphi 2010, to handle Return and Ctrl + Return in onkeyUp event, but it seems that they are not compatible.
What I want to do with this code is : if you press Enter in an edit it adds an element in a Listbox and if you press Ctrl+Enter it should modify the active element.
My code is this:
procedure TForm5.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if GetKeyState(VK_RETURN) < 0 then
lb1.items[lb1.ItemIndex]:=edit1.Text;
if GetKeyState(VK_CONTROL) < 0 then
case Key of
VK_RETURN:begin
lb1.Items.Add(Edit1.text);
lb1.ItemIndex:=lb1.Items.Count-1;
label3.caption:='NÂș de Registros:'+inttostr(lb1.Items.Count);
end;
and run when return and ctrl+return are used. However I don't seem to know what I'm doing wrong because I execute the code and when enter is pressed and also the code when Ctrl+enter is pressed.