键盘事件 (C++ Builder)

来源(怡园)

From: http://yynets.best.163.com/cbuilder.htm

键盘事件 (C++ Builder)

void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
        TShiftState Shift) {

    if( Shift.Contains(ssShift) ) // 如果按下了Shift键则在第一个面板上显示Shift
        StatusBar1->Panels->Items[0]->Text = "Shift";
    if( Shift.Contains(ssAlt)) // 如果按下了Alt键则在第二个面板上显示Alt
        StatusBar1->Panels->Items[1]->Text = "Alt";
    if( Shift.Contains(ssCtrl) ) // 如果按下了Ctrl键则在第三个面板上显示Ctrl
        StatusBar1->Panels->Items[2]->Text = "Ctrl";
    if( Shift.Contains(ssAlt)&&(Shift.Contains(ssCtrl))) // 如果同时按下了Alt+Ctrl键则在第二个面板上显示Alt+Ctrl
        StatusBar1->Panels->Items[5]->Text = "Alt+Ctrl";
}
//---------------------------------------------------------------------------


void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
        TShiftState Shift) {

    // 在Shift、Alt和Ctrl键弹起时清除状态栏中相应面板上的内容
    if( !(Shift.Contains(ssShift)) )
        StatusBar1->Panels->Items[0]->Text = "";
    if( !(Shift.Contains(ssAlt)) )
        StatusBar1->Panels->Items[1]->Text = "";
    if( !(Shift.Contains(ssCtrl)) )
        StatusBar1->Panels->Items[2]->Text = "";
    if( !Shift.Contains(ssAlt)&&(!Shift.Contains(ssCtrl)))
        StatusBar1->Panels->Items[5]->Text = "";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
        TShiftState Shift, int X, int Y) {

    if( Shift.Contains(ssLeft) ) // 如果按下了左键则在第四个面板上显示left
        StatusBar1->Panels->Items[3]->Text = "Left";
    if( Shift.Contains(ssMiddle) ) // 如果按下了中键则在第五个面板上显示Middle
        StatusBar1->Panels->Items[4]->Text = "Middle";
    if( Shift.Contains(ssDouble) ) // 如果是双击则在第六个面板上显示Double
        StatusBar1->Panels->Items[5]->Text = "Double";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
        TShiftState Shift, int X, int Y) {

    // 在鼠标按键弹起时清除状态栏中相应面板上的内容
    if( !(Shift.Contains(ssLeft)) )     StatusBar1->Panels->Items[3]->Text = "";
    if( !(Shift.Contains(ssMiddle)) )   StatusBar1->Panels->Items[4]->Text = "";
    if( !(Shift.Contains(ssDouble)) )   StatusBar1->Panels->Items[5]->Text = "";
}

Link: http://www.asm32.net/article_details.aspx?id=1916


浏览次数 435 发布时间 2006/8/25 7:39:11 从属分类 C/C++ 【评论】【 】【打印】【关闭
 
| www.asm32.net | 2006版 | 资料中心 | linux | asm/asm32 | C/C++ | VC++ | java | Python | 书签 | ASP.Net书签 | 京ICP备09029108号-1