开发者

Unregistering the Alt-Tab hotkey in Windows 7

开发者 https://www.devze.com 2023-01-08 05:57 出处:网络
I think this problem should be easy to solve, and I\'m bringing it here because I really feel like I\'ve looked everywhere for a solution.

I think this problem should be easy to solve, and I'm bringing it here because I really feel like I've looked everywhere for a solution.

My code is written in C# and should simply over write the Alt-Tab hotkey. This line works in XP but return false in 7:

RegisterHotKey(handle, ID__ALT_TAB, MOD_ALT,开发者_Go百科 VK_TAB)); 

I know that Windows 7 now requires that I unregister the hotkey before I can register my new one, and this is where the problem lies. When I check on the last error code I get code 1409, meaning the hotkey already exists. However if I call this line before the one above:

UnregisterHotKey(handle, ID__ALT_TAB)); 

That line fails and the last error code is set to 1419, meaning no such hotkey exists. These lines do work in XP, and I am able to register a hotkey and then unregister it. I beleive it is because I am attempting to unregister a hotkey with the wrong ID, as ID_ALT_TAB is self defined. I havent been able to find the correct ID of the Windows level Alt-Tab HotKey. Any help or general pointers would be greatly appreciated.


I don't think there is a way to do this. Not to mention, even if you manage to somehow register your hotkey overtop of the existing one, what happens when your application exits? Suddenly, there's no Alt-Tab at all.

Rather, I'd go with another shortcut to trigger your replacement. Maybe Ctrl-Alt-Tab?


Not sure if you've already seen this? Might have to a little work with C here. I would think you'd be able to intercept the Alt+Tab stroke using this code and then do whatever you wish in it's place, but I'm not sure.

EDIT: Also see this for some older VB work that you might have to translate into C#.


Did you also run the program as administrator (rather than just being logged in as Admin)? After XP programs don't necessarily get admin rights just because the user is admin, you could try right-click Run As Administrator (or similar).


UnregisterHotKey works fine and returns 0 when it is fired from the same tread where registration was done, so make sure that you unregister you hot keys from the same thread, otherwise it returns 1419. Tested on Vista.

0

精彩评论

暂无评论...
验证码 换一张
取 消