在按键处理的代码里填上 e.Handled = true; 就没声音了
private void textBoxCodebar_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == Convert.ToChar(Keys.Enter)) { button2_Click(sender, e); e.Handled = true; } }
来源: https://blog.csdn.net/shibing5238/article/details/7619505
如何才能使在Edit组件中按按下"Ctrl+A"时,不要发出'叮'的一声?
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); var vWinControl: TWinControl; begin vWinControl := FindControl(Msg.hwnd); if not (vWinControl is TEdit) then Exit; case Msg.message of WM_KEYDOWN, WM_KEYUP: begin if ssCtrl in KeyDataToShiftState(Msg.lParam) then case Msg.wParam of Ord('A'): Handled := True; end; case Msg.wParam of VK_RETURN, VK_ESCAPE: Handled := True; end; if Handled then vWinControl.Perform(Msg.message, Msg.wParam, Msg.lParam); end; end; end;
来源:https://bbs.csdn.net/topics/70056087
在不响应按键输入的窗口,每次按下时,都会发出“咚咚咚”的声音,如何去掉?
咚咚咚声本来是windows用来提醒用户,输入无效的。
既然你不想要,可以在PreTranslateMessage里返回TRUE,拿我一个控件为例,如果不做处理,按什么键都会发出咚咚咚声。但我的控件支持数字键:
BOOL CXXXXCtrl::PreTranslateMessage(MSG* pMsg) { if (WM_KEYDOWN != pMsg->message) return COleControl::PreTranslateMessage(pMsg); if (0x31 <= pMsg->wParam && pMsg->wParam <= 0x39) //数字键 { SelectLegendFromIndex(pMsg->wParam - 0x31); return TRUE; } return COleControl::PreTranslateMessage(pMsg); }
来源:https://bbs.csdn.net/topics/110182044
DELPHI OnKeyDown,OnKeyPress,OnKeyUp区别
有键按下 -> 产生onKeyDown事件 -> 如果是有ASCII码的按键, 则产生onKeyPress事件
有键释放 -> 产生onKeyUp事件
onkeydown和onkeypress的区别是有些键Shift、Ctrl、Alt、F1、F2、...等按键是不会产生onKeyPress事件的
如键盘的↑键onkeypress不会响应事件,但用onkeydown就可以响应
OnKeyPress 只能抓到数值或字母按键及 Esc键、空白键,但不含功能键(F1-F12)
OnKeyDown 能抓到所有的键(除 Tab 键)但不能分辨「对称键」的不同
OnShortCut 能抓到所有的键(含 Tab 键)且能分辨「对称键」的不同
注:「对称键」指的是左右两边皆有的键,如「Enter」、「Shift」、「Ctrl」、「Alt」等等
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if ssCtrl in shift then ShowMessage('ssCtrl');
shift 是一个集合变量。type TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble);
Value Meaning
ssShift The Shift key is held down.
ssAlt The Alt key is held down.
ssCtrl The Ctrl key is held down.
ssLeft The left mouse button is held down.
ssRight The right mouse button is held down.
ssMiddle The middle mouse button is held down.
ssDouble The mouse was double-clicked.
//============================================================================== // 去掉按回车键登录的声音 //============================================================================== procedure TFormLogin.FormKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then Key := #0; end;
说明:如果不想听到操作后的系统声音,并且如果不使用Shift、Ctrl、Alt、F1、F2、...等按键使用keypress
转自:https://blog.csdn.net/zengcong2013/article/details/17306685