Adam Plocher

Hello, I would like to build an app that acts similar to ALT+TAB (a key combination causes a form to pop up, hide the form when the keys arent held down anymore) and I'm just wondering what I would need to do to capture keys in Windows Will I need to access the Windows API directly to accomplish this Are there any examples that somebody could point me to that show how to do something in C# based on a KeyDown in Windows

Thanks!


Re: Visual C# General Capture Key Presses in Windows

Michael J. Brown

Adam,

I'm not entirely sure this is possible in C#, but you may want to check out http://www.codeproject.com/cs/system/CSLLKeyboard.asp

You may also want to look in to using SetWindowsHookEx in user32.dll. It's fairly trivial to call an external dll in C# (System.Interop).. a quick search on Google will probably bring up a bunch of results.






Re: Visual C# General Capture Key Presses in Windows

Gabriel Lozano-Moran

Adam Plocher wrote:
Hello, I would like to build an app that acts similar to ALT+TAB (a key combination causes a form to pop up, hide the form when the keys arent held down anymore) and I'm just wondering what I would need to do to capture keys in Windows Will I need to access the Windows API directly to accomplish this Are there any examples that somebody could point me to that show how to do something in C# based on a KeyDown in Windows

Thanks!

Here is how to do it: http://support.microsoft.com/Default.aspx id=320584






Re: Visual C# General Capture Key Presses in Windows

Michael J. Brown

I'm not sure that method will work unless the Control has focus.. as I understand it he wants to override Alt-Tab functionality and create his own Alt-Tab method in Windows.. is this correct or are you wanting similar functionality in your specific program




Re: Visual C# General Capture Key Presses in Windows

Gabriel Lozano-Moran

 Michael J. Brown wrote:
I'm not sure that method will work unless the Control has focus.. as I understand it he wants to override Alt-Tab functionality and create his own Alt-Tab method in Windows.. is this correct or are you wanting similar functionality in your specific program

I was under the impression that he wanted this in his application. Otherwise he should indeed use keyboard hooks. Anyway as far as I know special shortcuts like Alt + Tab and Ctrl + Alt + Delete are handled by the operating system and I don't think that you can intercept these.






Re: Visual C# General Capture Key Presses in Windows

micvos

Alt + Tab can be picked up by an application. Ctrl+Alt+Del is an exception. This is the only key combination which will not be propegated by the OS to what application whatever.




Re: Visual C# General Capture Key Presses in Windows

Peter Ritchie

It's not recommended that system-wide hooks, shared extensions, or system-wide extensions be written in a managed language like C# or VB.NET. For details see http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=125283&SiteID=1 and http://blogs.msdn.com/oldnewthing/archive/2006/12/18/1317290.aspx.




Re: Visual C# General Capture Key Presses in Windows

Adam Plocher

Thanks guys for all the replies, I'm not actually trying to over-ride ALT+TAB or CTRL+ALT+DELETE but I want to write an application that acts similar...

For example:

If I hold down ALT+` (tilde) have a form pop up and be able to scroll through items in it like the way ALT+TAB works (by keeping ALT held down but hitting the tilde button to scroll through items), then when you let go of ALT it would cause the form to disappear. So no matter what application has focus, when I hit ALT+` my application would pop up. I think most of it I can do, I just need to know how to capture that initial ALT+`....

Thanks!




Re: Visual C# General Capture Key Presses in Windows

Adam Plocher

Thanks Peter, that makes sense. It's too bad though... :(




Re: Visual C# General Capture Key Presses in Windows

Gabriel Lozano-Moran

 Peter Ritchie wrote:
It's not recommended that system-wide hooks, shared extensions, or system-wide extensions be written in a managed language like C# or VB.NET.  For details see http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=125283&SiteID=1 and http://blogs.msdn.com/oldnewthing/archive/2006/12/18/1317290.aspx

This should work fine: http://blogs.msdn.com/toub/archive/2006/05/03/589423.aspx, messages will be pumped to the threads that created the hook. I don't know what exactly you had in mind...