键盘上的power键一按就要关机了,请问有没有办法可以在按的时候拦截它给机器发送的消息而进行其他操作。
解决方案 »
- delphi程序拷贝到其他机子上出错。。
- listview中的字符串太长不能完全显示,有什么办法解决?
- 资源访问?
- up有分,如果人多可加分,寻行宽可随字段内容多少自动适应的dbgrid控件?
- 线程+报表fastreport
- 怎么样才能让 edit 里只输入数字
- 有谁知道,给100分!限上午11点前!
- 在编写VCL控件的时候,如何正确使用TSTRINGS的PROPERTY,谢谢
- 帮忙捉虫!在线焦急等待!
- CORBA是否或如何支持事务;COM+ OBJECT中事务支持的代码如何写呢?
- 关于Formula one 打印问题
- 怎样注册delphi7才能进入borland那个该死的downloads for registered users区?
step 2: 找到power键位接头,转接到某功能键如F12
step 3:在程序中拦截F12按下的消息
Intercepting The TAB and ENTER Keys{the prototype for the new keyboard hook function}
function KeyboardHook(nCode: Integer; wParam: WPARAM;
lParam: LPARAM): LResult; stdcall;var
Form1: TForm1;
WinHook: HHOOK; // a handle to the keyboard hook functionimplementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin {install the keyboard hook function into the keyboard hook chain}
WinHook:=SetWindowsHookEx(WH_KEYBOARD, @KeyboardHook, 0, GetCurrentThreadID);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
{remove the keyboard hook function from the keyboard hook chain}
UnhookWindowsHookEx(WinHook);
end;function KeyboardHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LResult;begin
{if we can process the hook information...}
if (nCode>-1) then
{...was the TAB key pressed?}
if (wParam=VK_TAB) then
begin
{if so, output a beep sound}
MessageBeep(0); {indicate that the message was processed}
Result := 1;
end
else
{...was the RETURN key pressed?} if (wParam=VK_RETURN) then
begin
{if so, and if the key is on the up stroke, cause
the focus to move to the next control}
if ((lParam shr 31)=1) then
Form1.Perform(WM_NEXTDLGCTL, 0, 0); {indicate that the message was processed}
Result := 1;
end
else
{otherwise, indicate that the message was not processed.} Result := 0
else
{we must pass the hook information to the next hook in the chain}
Result := CallNextHookEx(WinHook, nCode, wParam, lParam);
end;你可以试一下,不过肯定不行。Power是没有Virual Key code的。
如果你会写vxd的话就可以搞定你的问题了。
power~
procedure WMPowerBroadcast(var message: TMessage); message WM_POWERBROADCAST;procedure TForm1.WMPowerBroadcast(var message: TMessage);
begin
message.Result := BROADCAST_QUERY_DENY; {阻止系统关闭热键}
end;这是截取power键的代码