可以使用Delphi在W7中禁用任务切换键盘快捷键吗? [英] Can task-switching keyboard shortcuts be disabled in W7 using Delphi?

查看:122
本文介绍了可以使用Delphi在W7中禁用任务切换键盘快捷键吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年来,MY应用程序一直采用一种模式,客户可以在该模式下禁用对操作系统的访问。显然,此功能与实际情况不符(至少就Windows而言),但是在某些情况下,我的App是唯一应对机器操作员可见的程序,在这种情况下,此功能很有用。

MY application has had a mode for years where the customer can 'disable access to the OS'. Obviously this feature goes against the grain (at least as far as Windows is concerned) but there are installations where my App is the only program that should ever be visibile to a machine operator amd in this case such a feature is useful.

我使用的技术是从多个层构建的:

The technigue I used was built from several 'layers':


  1. 隐藏任务栏,然后

  2. 禁用任务切换。

  3. 禁用我的主表单系统图标。

要禁用我使用的任务栏:

To disable the taskbar I used:

// Get a handle to the taskbar and its button..
Taskbar := FindWindow('Shell_TrayWnd', Nil);
StartButton := FindWindow('Button', Nil);

// Hide the taskbar and button
if Taskbar <> 0 then
  ShowWindow( Taskbar, SW_HIDE );
if StartButton <> 0 then
  ShowWindow( StartButton, SW_HIDE );

// Set the work area to the whole screen
R := Rect( 0,0,Screen.Width,Screen.Height );
SystemParametersInfo(
  SPI_SETWORKAREA,
  0,
  @R,
  0 );

此方法运行良好,在W7上仍然不错。
几年前研究如何禁用任务切换,这是假装您的应用程序是屏幕保护程序的唯一技术(除了将应用程序重命名为 explorer.exe并启动该程序等可怕的事情之外) ):

This worked well and still seems fine on W7. Researching how to disable task-switching some years ago turned up the only technique of 'pretending' that your App is a screen saver (other than terrible things like renaming your app to 'explorer.exe' and booting into it etc):

procedure EnableTaskSwitching( AState : boolean );
// Enables / disables task switching
begin
  SystemParametersInfo(
    SPI_SCREENSAVERRUNNING,
    Cardinal( not AState),
    nil,
    0 );
end;

不足为奇的是,这似乎在W7中没有任何作用(我认为它在XP等系统中有效)。
有谁知道启用/禁用Alt-Tab(和其他特殊的Windows键)的另一种更好的方法吗?

Not surprisingly this seems to have no effect in W7 (I think it works in XP etc). Does anyone know of another, better, way of enabling / disabling Alt-Tab (and other special windows keys) from working?

推荐答案

如果找到了解决方案:

function LowLevelKeyboardProc(nCode: integer; wParam: WPARAM; lParam: LPARAM):
  LRESULT; stdcall;
type
  PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
  TKBDLLHOOKSTRUCT = record
    vkCode: cardinal;
    scanCode: cardinal;
    flags: cardinal;
    time: cardinal;
    dwExtraInfo: Cardinal;
  end;

  PKeyboardLowLevelHookStruct = ^TKeyboardLowLevelHookStruct;
  TKeyboardLowLevelHookStruct = TKBDLLHOOKSTRUCT;
const
  LLKHF_ALTDOWN = $20;
var
  hs: PKeyboardLowLevelHookStruct;
  ctrlDown: boolean;
begin

  if nCode = HC_ACTION then
  begin

    hs := PKeyboardLowLevelHookStruct(lParam);
    ctrlDown := GetAsyncKeyState(VK_CONTROL) and $8000 <> 0;
    if (hs^.vkCode = VK_ESCAPE) and ctrlDown then
      Exit(1);
    if (hs^.vkCode = VK_TAB) and ((hs^.flags and LLKHF_ALTDOWN) <> 0) then
      Exit(1);
    if (hs^.vkCode = VK_ESCAPE) and ((hs^.flags and LLKHF_ALTDOWN) <> 0) then
      Exit(1);
    if (hs^.vkCode = VK_LWIN) or (hs^.vkCode = VK_RWIN) then
      Exit(1);

  end;

  result := CallNextHookEx(0, nCode, wParam, lParam);

end;

procedure TForm1.FormShow(Sender: TObject);
begin
  SetWindowsHookEx(WH_KEYBOARD_LL, @LowLevelKeyboardProc, 0, 0);
end;

这将禁用(如您所见!)

This disables (as you can see!)


  • Ctrl + Esc(显示开始菜单)

  • Alt + Tab(任务切换)

  • Alt + Esc (任务切换)

  • Win(显示开始菜单)

  • Win + Tab(3D任务切换)

  • Win + D,Win + M,Win + Space,Win +箭头,Win + P,Win + U,Win + E,Win + F,Win + Digit,...

  • 包括Windows键在内的几乎所有组合(但不是全部,例如Win + L)

  • Ctrl+Esc (show start menu)
  • Alt+Tab (task switch)
  • Alt+Esc (task switch)
  • Win (show start menu)
  • Win+Tab (3D task switch)
  • Win+D, Win+M, Win+Space, Win+Arrows, Win+P, Win+U, Win+E, Win+F, Win+Digit, ...
  • Almost any combination including the Windows key (but not all, e.g. Win+L)

这篇关于可以使用Delphi在W7中禁用任务切换键盘快捷键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆