谁有禁用win键的代码,越简单越好。(50)

  • 主题发起人 主题发起人 eye0eye
  • 开始时间 开始时间
我有。我给你找找,留下油箱
 
unit WHookInt;interfaceuses Windows, Messages, SysUtils; function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall; export; function FreeHook: Boolean; stdcall; export; function MsgFilterFunc(Code: Integer; wParam, lParam: Longint): Longint stdcall; export;implementationfunction CreateMMF(Name: string; Size: Integer): THandle;begin Result := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, Size, PChar(Name)); if Result <> 0 then begin if GetLastError = ERROR_ALREADY_EXISTS then begin CloseHandle(Result); Result := 0; end; end;end;function OpenMMF(Name: string): THandle;begin Result := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, PChar(Name)); // The return value is an open handle to the specified file-mapping object.end;function MapMMF(MMFHandle: THandle): Pointer;begin Result := MapViewOfFile(MMFHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);end;function UnMapMMF(P: Pointer): Boolean;begin Result := UnmapViewOfFile(P);end;function CloseMMF(MMFHandle: THandle): Boolean;begin Result := CloseHandle(MMFHandle);end;type TPMsg = ^TMsg;const VK_D = $44; VK_E = $45; VK_F = $46; VK_M = $4D; VK_R = $52; MMFName = 'MsgFilterHookDemo';type PMMFData = ^TMMFData; TMMFData = record NextHook: HHOOK; WinHandle: HWND; MsgToSend: Integer; end; // global variables, only valid in the process which installs the hook.var MMFHandle: THandle; MMFData: PMMFData;function UnMapAndCloseMMF: Boolean;begin Result := False; if UnMapMMF(MMFData) then begin MMFData := nil; if CloseMMF(MMFHandle) then begin MMFHandle := 0; Result := True; end; end;end;function SetHook(WinHandle: HWND; MsgToSend: Integer): Boolean; stdcall;begin Result := False; if (MMFData = nil) and (MMFHandle = 0) then begin MMFHandle := CreateMMF(MMFName, SizeOf(TMMFData)); if MMFHandle <> 0 then begin MMFData := MapMMF(MMFHandle); if MMFData <> nil then begin MMFData.WinHandle := WinHandle; MMFData.MsgToSend := MsgToSend; MMFData.NextHook := SetWindowsHookEx(WH_GETMESSAGE, MsgFilterFunc, HInstance, 0); if MMFData.NextHook = 0 then UnMapAndCloseMMF else Result := True; end else begin CloseMMF(MMFHandle); MMFHandle := 0; end; end; end;end;function FreeHook: Boolean; stdcall;begin Result := False; if (MMFData <> nil) and (MMFHandle <> 0) then if UnHookWindowsHookEx(MMFData^.NextHook) then Result := UnMapAndCloseMMF;end;function MsgFilterFunc(Code: Integer; wParam, lParam: Longint): Longint;var MMFHandle: THandle; MMFData: PMMFData; Kill: boolean;begin Result := 0; MMFHandle := OpenMMF(MMFName); if MMFHandle <> 0 then begin MMFData := MapMMF(MMFHandle); if MMFData <> nil then begin if (Code < 0) or (wParam = PM_NOREMOVE) then { The CallNextHookEx function passes the hook information to the next hook procedure in the current hook chain. } Result := CallNextHookEx(MMFData.NextHook, Code, wParam, lParam) else begin Kill := False; { Examples } with TMsg(Pointer(lParam)^) do begin // Kill Numbers if (wParam >= 48) and (wParam <= 57) then Kill := True; // Kill Tabulator if (wParam = VK_TAB) then Kill := True; end; { Example to disable all the start-Key combinations } case TPMsg(lParam)^.message of WM_SYSCOMMAND: // The Win Start Key (or Ctrl+ESC) if TPMsg(lParam)^.wParam = SC_TASKLIST then Kill := True; WM_HOTKEY: case ((TPMsg(lParam)^.lParam and $00FF0000) shr 16) of VK_D, // Win+D ==> Desktop VK_E, // Win+E ==> Explorer VK_F, // Win+F+(Ctrl) ==> Find:All (and Find: Computer) VK_M, // Win+M ==> Minimize all VK_R, // Win+R ==> Run program. VK_F1, // Win+F1 ==> Windows Help VK_PAUSE: // Win+Pause ==> Windows system properties Kill := True; end; end; if Kill then TPMsg(lParam)^.message := WM_NULL; Result := CallNextHookEx(MMFData.NextHook, Code, wParam, lParam) end; UnMapMMF(MMFData); end; CloseMMF(MMFHandle); end;end;initialization begin MMFHandle := 0; MMFData := nil; end;finalization FreeHook; end.
 
楼上的可以实现,我的也找到了。unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type // Declaration from VC++ WINUSER.H // PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT; KBDLLHOOKSTRUCT = record vkCode: DWORD; scanCode: DWORD; flags: DWORD; time: DWORD; dwExtraInfo: DWORD; end;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; hhklowlevelkybd : HHOOK;implementation{$R *.dfm}function LowLevelKeyboardProc(nCode:integer;WParam:WPARAM;LParam:LPARAM):LRESULT;stdcall;var fEatKeystroke:BOOL; p:PKBDLLHOOKSTRUCT;begin result:=0; fEatKeystroke := false; p:=PKBDLLHOOKSTRUCT(lparam); if (ncode=HC_ACTION) then begin case wparam of WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP: featkeystroke :=(p.vkcode = VK_Lwin) or (p.vkcode = VK_Rwin)or (p.vkcode = VK_apps); end; end; if featkeystroke = 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;beginhhklowlevelkybd := setwindowshookexw(wh_keyboard_ll,LowlevelKeyboardproc,hinstance,0);end;procedure TForm1.Button2Click(Sender: TObject);beginUnhookWindowsHookEx(hhkLowLevelKybd);end;end.
 
最简单的方法:买一个没有win键的键盘
 
把win键弄掉
 
不用那么麻烦,在Win键附近灌点水就好了。
 
后退
顶部