Let's consider the following scenario: In my desktop machine i have two applications opened side by side, a browser and a text editor(half size of the display for each application).

How can I switch between those two applications, but without using alt-tab or win-tab or mouse clicks?

If is nothing default built on windows xp/vista or 7 how can I do that programmatically using c++? For example to press alt+l(or alt+1), to activate the left window and the alt+r(alt+2) to activate the right window.

thanks

link|improve this question

56% accept rate
Why the close votes? The words "C++" and "programmatically" definitely make this a programming question. – Thomas Dec 10 '09 at 19:16
@Thomas As I read it, OP is asking for a built-in capability or an existing app, or short of that "how can I do it", which is far too vague for an SO programming question. – Tim Sylvester Dec 10 '09 at 19:20
feedback

migrated from stackoverflow.com Dec 10 '09 at 19:17

This question came from our site for professional and enthusiast programmers.

4 Answers

Create an AutoHotKey script to grab those keyboard shortcuts and activate the program you want.

link|improve this answer
feedback

If you have the handles to those windows, you can use SetForegroundWindow.

You can get a windows handle if you know the title with FindWindow. This article explains how to get a window handle if you partially know the title (non-exact match), though I've never tried.

For your hot-keys, look at SetWindowsHookEx with WH_KEYBOARD as the hook type. You'll make a KeyboardProc, which Windows will call on key-presses. Here, you can capture your specific key-combinations and activate certain windows.

That said, Windows provides hot-keys for you, as outlined in other answers.

link|improve this answer
feedback

On Windows 7, you can switch to any of the first ten items on the taskbar (whether running or not) by pressing Windows+(1..0). You can drag taskbar items around to change the order.

link|improve this answer
This works a little different in Vista: Windows-1..9 opens the corresponding quick link from the bar next to your start menu – Jorn Dec 10 '09 at 19:14
Yes, which doesn't answer the question. That's why I said On Windows 7. – SLaks Dec 10 '09 at 19:19
feedback

Use this AutoHotKey script:

~LAlt & Tab::Send ^#{Tab}
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.