How do you disable system hotkeys in user32.dll?

别来无恙 提交于 2019-11-28 12:44:44

问题


I am coding in C#, if it is relevant.

I am trying to disable system hotkeys for a kiosk application. The code used here has come from: https://www.codeproject.com/kb/cs/kiosk_cs.aspx?display=print

This individual: How to disable the pressing/holding down of the Alt key, Control Key, and Shift Key when the left mouse button is clicked has appeared to have successfully used this method to disable Alt + F4 on Windows. However she didn't explicitly specify which version of Windows she was using other than saying one of the commands didn't work in W8.

Tutorial for those who don't understand the code: https://www.youtube.com/watch?v=qQWqGOaZiFI


I tried it.

RegisterHotKey(this.Handle, int 1, (int)USE_ALT, (int)Keys.F4);

^ keeps failing though.

Marshal.GetLastWin32Error().ToString()

When ^ runs, it returns the error code "1400".

Enum of errors: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681385(v=vs.85).aspx. This suggests this is a result of an "Invalid window handle.". I don't know why this is because "Alt + F4" closes the current selected window. I'm pretty sure that's what FindWindow(string cls, string wndwText) returns.

I added "SetLastError = true" in:

[DllImport("user32.dll", SetLastError = true)] private static extern int RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);

Now, registering "Alt + F4" returns "1409", which means "Hot key is already registered". Which is exactly the point. It's already registered and for this kiosk application, I need to disable that temporarily. My research on this has shown that I need to use user32.dll to create hooks. Which is exactly what I am doing or trying to do.

Have I missed something?

I still need a sure-proof way to block Alt + F4 as well as other system hotkeys. However the other hotkeys: CTRL+W, CTRL+N, CTRL+S, CTRL+A, CTRL+C, CTRL+X, CTRL+V, CTRL+B, CTRL+F and CTRL+H have successfully been blocked on Windows 10 and 8.1.


Useful Information

  • It's worth noting this code was compiled (Build > Publish), installed and run on W8.1. Alt + F4 was successfully blocked... somehow. However, the other two system hotkeys Alt + Tab and Home + Up fail to register for the same reason: "1409" - "Hot key is already registered".
  • Running in W8 compatibility mode on W10 does not give me the same result as W8.1.
  • I am running the app in Administrator's mode.
  • Alt + F4 is just one of the many system hotkeys I want to disable. It's not the only one.

来源:https://stackoverflow.com/questions/43260744/how-do-you-disable-system-hotkeys-in-user32-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!