Zato ce ti Qt.hpp? To ti uopste ne treba za hvatanje OnKey...() dogadjaja.
Qt je CLX biblioteka u povezana je sa Linux-om.
Ako ti treba samo hvatanje nekog tastera koji je povezan sa nekim od sistemskih
tastera za modifikovanje (Ctrl, Alt,Shift), onda mozes ovako:
Code:
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Shift.Contains( ssCtrl ) )
{
if ( Key == '1')
{
ShowMessage( "CTRL+1" );
}
}
}
A, ako ti treba stvarno vise tastera, onda mozes ovako:
Code:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Key81Pressed = false; // Q
Key87Pressed = false; // W
Key69Pressed = false; // E
}
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( !Key81Pressed && Key == 'Q' )
Key81Pressed = true;
if ( !Key87Pressed && Key == 'W' )
Key87Pressed = true;
if ( !Key69Pressed && Key == 'E' )
Key69Pressed = true;
if ( Key81Pressed && Key87Pressed && Key69Pressed )
{
Key81Pressed = false;
Key87Pressed = false;
Key69Pressed = false;
ShowMessage( "Q+W+E je pristisnuto!" );
}
}
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == 'Q' ) Key81Pressed = false;
if ( Key == 'W' ) Key87Pressed = false;
if ( Key == 'E' ) Key69Pressed = false;
}
U svakom slucaju, savetujem ti da property KeyPreview postavis na true:
Code:
KeyPreview = true;
...sto mozes uraditi i u ObjectInspector-u. Ovo ce ti omoguciti hvatanje dogadjaja
OnKey...() na glavnoj formi cak i kada je prekrivena nekim drugim objektima koji u
sebi takodje imaju OnKey...() dogadjaj i trenutno su fokusirani.