Link to home
Start Free TrialLog in
Avatar of carceri
carceri

asked on

Disable windows keys

I want to write a program to intercept windows keypresses and prevent that keypress from being detected by windows. Also, I would like to remap that keypress to another key. My biggest problem is that this must also work for the three windows specific keys (and they're causing me much trouble). If anyone know how to do this it would be much appreciated...

Regards,
  Michael
Avatar of WxW
WxW

You need to install a message hook . SetWindowsHookEx() with WH_CALLWNDPROC or WH_GETMESSAGE . Then you can decide if you want to pass any WM_KEYDOWN , WM_CHAR , or WM_SYSKEYDOWN to the application.
Avatar of carceri

ASKER

And if I don't want to pass any of those to the application, how can I tell it not to. By the return value of the function?

Regards,
  Michael
Avatar of carceri

ASKER

And if I don't want to pass any of those to the application, how can I tell it not to. By the return value of the function?

Regards,
  Michael
Avatar of carceri

ASKER

Hmmm, if you just post a comment without checking any of the boxes it defaults to accept the answer (or so it appers :-)

And if you reload the page, it posts the comment again...
Sorry - I thought that you could prevent the message from being sent . You can discard my answer =(
Avatar of carceri

ASKER

I can prevent "normal" keystrokes from being sent, but somehow I can't just block the windows keys. I can prevent all the system keys, but there apper to be special rules for the windows keys. Sorry if I wasn't clear enough in my question

Regards,
  Michael
What keys do you want to prevent exactly?

Ctrl-Esc, Alt-Tab, Ctrl-Shift-Esc??
Avatar of carceri

ASKER

I want to prevent the three windows keys from working. They are very annoying and I always hit them at the wrong time. I would also like to remap these keys to something else...

I can of cause block all HCBT_SYSCOMMAND keys, but then I also block keys like Ctrl-Esc etc... and that's not what I want.

The win32.hlp file says that if I place a WH_KEYBOARD and a WH_CBT hook, I should be able to (when the code in the WH_CBT procedure is HCBT_KEYSKIPPED) edit items in the system message queue (eg remove the keys I don't want processed or/and insert another key) but I never get the HCBT_KEYSKIPPED code in WH_CBT procedure...

If I can get this code, I think that I can disable these keys...
Avatar of carceri

ASKER

Hmm... I was wrong... being able to trap the key in the CBTHookProc won't help me discard or remap the message:

function CBTHookProc(nCode: Integer; wparam: WPARAM; lparam: LPARAM): LRESULT stdcall;
begin
  if (nCode = HCBT_KEYSKIPPED) and ((WPARAM = 91) or (WPARAM = 92) or (WPARAM = 93)) then
  Result := 1 else Result := CallNextHookEx(hCBTHook, nCode, wParam, lParam);
end;

A return value different from 0 should make it clear that the message should not be processed, but it still is. If I remove the else part windows locks up, since no messages get processed (it stops all messages comming it's way)

I can't see why the above code won't work...

btw... WPARAM 91 92 and 93 are the three windows keys
To REALLY intercept system keystrokes YOU NEED a VxD.
There's no other way to do that.

Many people asked the same question.

Look my answer at https://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=10045464 . It could help you.

Regards,
Jorge
ASKER CERTIFIED SOLUTION
Avatar of chrismal
chrismal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of carceri

ASKER

I am looking into the VxD issue. Disableling them for a start would do, but I would like to remap them to other keys, like you can easily do in Linux.

I can trap the keys, but not prevent them from reaching their destination. To register as a screen saver works, but also blocks eg Ctrl-Esc and that's not what I want.