Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable normal behaviour of Alt key?

Normally the Alt key opens the menu in Windows.

I need this to be disabled, because I need Alt key for my application. (It is an emulator of old computer, so I need to mimic its behaviour.) I write it in pure Windows API, so I expect there must be some message which is sent and needs to be disabled, discarded or ignored.

Alt+Tab is no problem, as well as other system keys and key combinations, I just need to ignore Alt when it opens the menu.

(My application uses DirectInput to read the keys, so it works well. I just need to disable the functionality which opens the menu with Alt key. I will open the menu using mouse.)

like image 906
Al Kepp Avatar asked Mar 09 '12 00:03

Al Kepp


People also ask

How do I disable my Alt key?

The default mode is turned on. However, workarounds are available depending on what you plan to do with the Alt Gr key. 1] If you have an Alt Gr key on your computer, you can disable it by pressing the shift key and the control key at the same time.

Why is my Windows key and Alt switched?

The reason your Left Alt key and Windows key have switched functions is likely that you are using a wireless keyboard that has two modes: Windows and Mac Mode. So, to fix this you need to find a switch on your keyboard and toggle it to Windows/Android mode.


1 Answers

How about checking for WM_SYSCOMMAND, and when wParam is SC_KEYMENU, return 0?

Update / exact solution:

if(wParam==SC_KEYMENU && (lParam>>16)<=0) return 0;
return DefWindowProc(hwnd, message, wParam, lParam);

Description: If lParam>>16 is positive then menu is activated by mouse, when it is zero or negative then menu is activated by Alt or Alt+something.

like image 115
Mike Kwan Avatar answered Sep 19 '22 20:09

Mike Kwan