要崩溃了!找了一个晚上的任何屏蔽xp下的左或右win键,都不成功,求救! ( 积分: 100 )

  • 主题发起人 主题发起人 mr.hl
  • 开始时间 开始时间
M

mr.hl

Unregistered / Unconfirmed
GUEST, unregistred user!
找了一个晚上的任何屏蔽xp下的左或右win键,都不成功,注意我要的是所有状态下都屏蔽win键,不是在我的程序中屏蔽.比较好的一个刘麻子的,
============================动态链接库代码如下(您可以命名为hook.dpr)============直接把这部分拷贝到txt,然后改扩展名为dpr,之后编译得到dll

library HookDll;

uses windows;

var
HookH:HHook=0;//钩子句柄

//=====键盘 钩子回调 函数
function keyhook(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
begin { 当Ctrl处于按下状态 }
if (( GetKeyState(VK_CONTROL) and $8000 )<>0) and (wParam=ord('P'))
then Result:=1//屏蔽
else Result:=CallNextHookEx(HookH,code,Wparam,lParam);
end;

procedure HookOn; //挂钩
begin
HooKH:=SetWindowsHookEx(WH_KEYBOARD,@keyHook,HInstance,0);
end;

procedure HookOff;//脱钩
begin
UnHookWindowsHookEx(HookH);
end;

exports //导出函数
HookOn,HookOff;
begin

end.
编译之后,我们在程序中调用 HookOn 即可。。

======================exe中:
.............
implementation

{$R *.dfm}
//引入动态连接库中函数
procedure HookOn ; external 'hook.dll';
procedure HookOff ; external 'hook.dll';
........
需要屏蔽的时候 HookOn;
需要恢复的时候 HookOff;

/////////////什么回车都能屏蔽,就是VK_LWIN没用!!!
谁给个方法吧...屏蔽xp下左或右win键,要能给出屏蔽win键和其他比如ALT+F4键的更好!谢谢.
 
关注关注关注关注关注关注
 
那年黄梅花开
 
用低级键盘钩子 WH_KEYBOARD_LL


http://www.delphibbs.com/delphibbs/dispq.asp?lid=3647310

library KeyHook;

uses
Windows,Messages;
var
MyHook: HHOOK;
function KeyHookProc(icode: integer;wparam:WPARAM; lparam: LPARAM):LRESULT;stdcall;
begin
Result:= 0;
if icode < 0 then
Result:= CallNextHookEx(MyHook,icode,wparam,lparam)
else
begin
if ((GetKeyState(VK_MENU) and $80) <> 0) and (wparam =VK_F4) then
Result:=1;
end;
end;

function InstallKeyHook:boolean;stdcall;
begin
MyHook:= 0;
MyHook:= SetWindowsHookEx(WH_KEYBOARD,@KeyHookProc,Hinstance,0);
Result:= (MyHook<>0);
end;

function UnInstallKeyHook:boolean;stdcall;
begin
Result:= False;
if MyHook <> 0 then
begin
UnHookWindowsHookEx(MyHook);
MyHook:=0;
end;
Result:= MyHook = 0;
SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);//广播消息
end;

exports
InstallKeyHook,UnInstallKeyHook;
begin

end.

aLt+ f4
 
凭感觉就知道可能不会结帖。。。
我上面的回答已经解决问题,因为自己试过了。
只是keyboard hook问题,修改下hook函数即可。
没意思。。。
 
在2ccc.com上有个开机保护窗的代码!!!里面有屏蔽xp下的左或右win键的代码!!!
快为我加分吧!!!!!
 
to 那年黄梅花开
请问您的回答在哪里?
如果可以我怎么会不给分呢?

to iyesno
请给出详细网址可以么?
 
我将 ysp娃娃 的
begin
if ((GetKeyState(VK_MENU) and $80) <> 0) and (wparam =VK_F4) then
Result:=1;
end;
改为
begin
if (wparam =VK_LWin) then
Result:=1;
end;
左win键还是没有屏蔽,不信你试试看?
应该怎么改呢?
 
上面都太麻烦,我估计你是要把WINDOWS的IE桌面全部去掉吧,用你自己的程序取代
如果是这样,那就好办了,你把自己的程序复制到WINDOWS目录
1.找出所有的EXPLORER.EXE文件
2.写一个复制文件的BAT批处理文件,同时把所有的EXPLORER文件换成你的程序,要最后去复制WINDOWS目录下的那个
3.结束掉EXPLORER进程,手工结束,不能想用命令来动态结束,没用的
4.CTRL+ALT+DEL运行你的那个复制文件的BAT,就可以了
 
希望你说话算话。
把你得hook函数该为下面得即可。
function keyhook(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
type
PtempRec= ^tempRec;
tempRec = record
vkCode: dword;
end;
begin
if (PtempRec(lParam).vkCode= VK_LWIN) or (PtempRec(lParam).vkCode= VK_RWIN)then
Result:=1
else
Result := CallNextHookEx(KeyHook, Code, wParam, lParam);
end;
 
library hidewin;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
windows,
messages;

var
hHk :HHOOK;
type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;

function ycxsks( yc:Boolean): Boolean;stdcall; //隐藏-显示任务条
var
h:THandle;
begin
if yc = True then
begin
h:=FindWindow('Shell_TrayWnd',nil);
ShowWindow(h,SW_hide); //隐藏任务条
end
else
begin
h:=FindWindow('Shell_TrayWnd',nil);
ShowWindow(h,SW_SHOW); //显示任务条
end;
Result:=true;
end;

function keyHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
//调用键盘钩子,屏蔽左右win功能键
var
p: PKBDLLHOOKSTRUCT;
y: integer;
begin
// if hHk <> 0 then
begin
if nCode<0 then
begin
Result:= CallNextHookEx(hHk,nCode,WParam,LParam)
end
else
begin
y := 0;
case WParam of
WM_KEYDOWN,WM_SYSKEYDOWN: //按键后判断所按键
begin
p:=PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = VK_LWIN then
y := 1;
if p^.vkCode = VK_RWIN then
y := 1;
end;
WM_KEYUP,WM_SYSKEYUP: //松开按键后判断所按键
begin
p:=PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = VK_LWIN then
y := 1;
if p^.vkCode = VK_RWIN then
y := 1;
end;
end;
if y=1 then
begin
if hHk <> 0 then
Result:=1 //如果为WIN功能键则屏蔽
else
begin
Result:=nCode;
end;
end
else
Result:= CallNextHookEx(hHk,nCode,WParam,LParam); //其他键放下一个钩子
end;
end

end;

function Enablehide:Boolean;stdcall;export; //外部调用
begin
if hHk = 0 then
begin
hHk := SetWindowsHookEx(13,@keyHookProc,HInstance,0);
Result := True;
end
else
Result := False;
//ycxsks(true);
end;

function Disablehide:Boolean; stdcall; export; //外部调用
begin
if hHk <> 0 then
begin
UnHookWindowsHookEx(hHk);
hHk := 0;
Result := True;
end
else
Result := False;
//ycxsks(False);
end;

exports
Enablehide,
Disablehide;
end.
 
呵呵,再看看就准备结贴了.
to mlssyy:你的代码可以成功屏蔽win键.
to 那年黄梅花开
我将程序改为你写的部分
library HookDll;
uses windows;
var
HookH:HHook=0;//钩子句柄
//=====键盘 钩子回调 函数
function keyhook(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
type
PtempRec= ^tempRec;
tempRec = record
vkCode: dword;
end;
begin
if (PtempRec(lParam).vkCode= VK_LWIN) or (PtempRec(lParam).vkCode= VK_RWIN) then
Result:=1
else
Result := CallNextHookEx(HookH, Code, wParam, lParam);
///////你的是 Result := CallNextHookEx(KeyHook, Code, wParam, lParam);我改了一下
end;

procedure HookOn; //挂钩
begin
HooKH:=SetWindowsHookEx(WH_KEYBOARD,@keyHook,HInstance,0);
end;

procedure HookOff;//脱钩
begin
UnHookWindowsHookEx(HookH);
end;

exports //导出函数
HookOn,HookOff;
begin

end.
///////////////////////但是奇怪的是.还是不行,偶尔会屏蔽win键,多按几次win键,就屏蔽不了了...如果你的可以的话,请完整一点给出.谢谢哈!
后来我找到了以下代码,成功屏蔽:
var
Form1: TForm1;
//定义句柄
OldHook:HHOOK;// 钩子 句柄

function LowLevelKeyboardProc(nCode:integer;WParam:WPARAM;LParam:LPARAM):LRESULT;stdcall;
type
KBDLLHOOKSTRUCT=record
vkCode:DWORD;
scanCode:DWORD;
flags:DWORD;
time:DWord;
dwExtraInfo:dword;
end;
var
fFlag:BOOL;
p:^KBDLLHOOKSTRUCT;
begin
result:=0;
fFlag := false;
p:=Pointer(LPARAM);
if (ncode=HC_ACTION) then
begin
case wparam of
WM_KEYDOWN,
WM_SYSKEYDOWN,
WM_KEYUP,
WM_SYSKEYUP:
fFlag :=(p.vkCode = VK_Lwin) or (p.vkCode = VK_Rwin)or (p.vkCode = VK_apps);
end;
end;
if fFlag = true then
Result:=1;
if ncode <> 0 then
Result := CallNextHookEX(0,ncode,wparam,lparam);
end;

procedure TForm1.Button1Click(Sender: TObject);
const
WH_KEYBOARD_LL=13;
begin
//注册 钩子
OldHook := setwindowshookexw(WH_KEYBOARD_LL,LowlevelKeyboardproc,hinstance,0);
end;

//卸载 钩子
procedure TForm1.Button2Click(Sender: TObject);
begin
if OldHook>0 then
UnhookWindowsHookEx(OldHook);
end;
 
怎么可能,要是没搞定,我把头拿给你当球踢。

library HookDll;
uses
Windows,
SysUtils,
Messages,
unit1;
var
KeyHook: HHook;

//hook函数
function HookKey(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
type
PtempRec= ^tempRec;
tempRec = record
vkCode: dword;
end;
begin
if (PtempRec(lParam).vkCode= VK_LWIN) or (PtempRec(lParam).vkCode= VK_RWIN)then
Result:=1
else
Result := CallNextHookEx(KeyHook, Code, wParam, lParam);
end;

procedure BeginHook;
begin
KeyHook := SetWindowsHookEx(13{=WH_KEYBOARD_LL}, @HookKey, HInstance, 0);
end;

procedure EndHook;
begin
UnhookWindowsHookEx(KeyHook);
end;

exports
BeginHook, EndHook;

begin
end.
*********************************
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure BeginHook ; external 'HookDll.dll';
procedure EndHook ; external 'HookDll.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
BeginHook;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
EndHook;
end;

end.
 
问题出在这里:
MyHook:= SetWindowsHookEx(WH_KEYBOARD,@KeyHookProc,Hinstance,0);
------->
KeyHook := SetWindowsHookEx(13{=WH_KEYBOARD_LL}, @HookKey, HInstance, 0);
这下ok了!感谢 那年黄梅花开!
 
后退
顶部