Forbid language switch for certain application(s)

4

I have a problem of accidental input language switch. I tried many different settings in order to not do it - change hotkey, install some software (Key Switcher, Keyboard Ninja, Punto Switcher)... But nothing helped.

I used to certain hotkey (Ctrl+Shift). Any other hotkey make me even more suffer. The software I found has no feature to avoid accidental switches.

What I want is to find a piece of software which can stick "English US" input language to my "Visual Studio". And any Ctrl+Shift pushes inside VS should not lead to language switch. Have any ideas?

Vasyl Boroviak

Posted 2010-04-30T08:43:42.103

Reputation: 617

What version of Windows and what version of Visual Studio? Also, 32 or 64-bit? – Hugh Allen – 2010-05-28T06:54:13.103

I'm working with Windows 7 and VS2008 (soon will switch to VS2010). All 64bit. – Vasyl Boroviak – 2010-05-28T07:31:27.717

Have you solved this issue? I'm having same problem... – alexeit – 2011-08-02T03:58:49.677

Nope, I didn't. – Vasyl Boroviak – 2011-08-02T12:17:30.820

it's 2014, there are flying robots outside, but we still can't solve it. still no solution? – vorou – 2014-05-27T03:03:24.463

Answers

1

If you go to
Control Panel / Regional and Language Options / Languages / Details / Key Settings
you'll find that you can define hotkeys for language changes.

You may couple this with a macro language like AutoHotkey, to define a macro that changes the language/keyboard-layout and then launches Visual Studio. This however won't block future language-changes.

If you're looking for something much stricter than that, as far as I know no such program exists. As VS is extensible, you can program yourself an add-in that will limit the number of languages allowed for VS. This small add-in will load with VS and set the preferred languages to just one (english).

If you wish to launch yourself in this direction, the following links might be helpful for a start:

Supporting Application-Specific Language Settings
Tutorial : Creating Visual Studio Add-Ins
Creating Visual Studio Add-Ins

harrymc

Posted 2010-04-30T08:43:42.103

Reputation: 306 093

Yeah. Remove all the language-switch hotkeys and leave only the indicators in the task bar. That way you can't accidentally switch. – Loren Pechtel – 2010-10-03T16:05:38.747

0

As long as your default language is already set and you only need to change the language for one program I would suggest changing the language for that program (VS) and then going into the Language Options and changing the hotkey to none, and then go to the key sequence and uncheck that box (Regional and language options -> Languages tab -> details -> Key Settings -> Change Key Sequence). Now the shortcuts will be off, and since Windows remembers inputs on a per application basis the input will automatically switch for VS but remain Spanish for everything else.

Daisetsu

Posted 2010-04-30T08:43:42.103

Reputation: 5 195

Nope. This is not the solution. The matter is I have to use both languages in all other applications (like browser, or mail client, or skype). – Vasyl Boroviak – 2010-05-27T08:45:11.407

0

The following works in Visual Studio .NET 2003 on WinXP 32-bit. YMMV.

  • File -> New Project
  • select Project Type: Other Projects \ Extensibility Projects
  • select template: Visual Studio .NET Add-in. Click OK.
  • click Next, select Create an Add-in using Visual C++ / ATL, click Next.
  • select all possible appication hosts, click Next.
  • (optionally) enter a name and description, click Next.
  • choose Options. Don't check "yes, create a Tools menu item". Click Next.
  • don't choose to create an About box. Click Next.
  • click Finish.
  • switch to the tab with the source file Connect.cpp
  • at the top, after the #includes add the line

    HHOOK myhook;
    
  • to method CConnect::OnConnection add the line

    myhook=SetWindowsHookEx(WH_GETMESSAGE, &myGetMsgProc, _AtlModule.GetResourceInstance(), GetCurrentThreadId());
    
  • to method CConnect::OnDisconnection add the line

    UnhookWindowsHookEx(myhook);
    
  • above OnConnection() add the function

    LRESULT CALLBACK myGetMsgProc(int code, WPARAM wParam, LPARAM lParam)
    {
        MSG *msg = (MSG*)lParam;
        if (code>=0 && msg->message==WM_INPUTLANGCHANGEREQUEST)
            msg->message = WM_NULL;
        return CallNextHookEx(myhook, code, wParam, lParam);
    }
    
  • build the solution.
  • select menu Tools -> Add-in Manager...
  • check the box for your new add-in. Don't check "Startup" for now in case anything went wrong - you don't want Visual Studio crashing every time it starts!
  • click OK.

It is now impossible to change language or keyboard layout in Visual Studio. The language bar gets a little confused if you try, but doesn't break.

Hugh Allen

Posted 2010-04-30T08:43:42.103

Reputation: 8 620

I did all the steps. All went fine. Except the language switch still happens. :( – Vasyl Boroviak – 2010-05-28T15:14:13.533

Damn. My code assumes that the thread which loads the addin is the thread which hosts the GUI, which may not be true in your version of VS. Could you find out if that is the problem? One way is to put a MessageBox() call in OnConnection to show the current thread id, and use Spy++ on the code editor window to find its thread id. – Hugh Allen – 2010-05-28T22:31:38.460

I just had another thought - did you actually try typing after switching languages, or did you just believe what the language bar told you? – Hugh Allen – 2010-05-29T02:57:38.820

I was typing of course. :) And restarted the VS just in case. I'll try the thread idea in two days. Thanks. – Vasyl Boroviak – 2010-05-29T18:36:42.623

@Vasiliy Borovyak: "try the thread idea in two days"... but the bounty ends in 2 days :( – Hugh Allen – 2010-05-30T00:07:14.560

@Vasiliy Borovyak: if you are hoping to get back your 100 rep points by not awarding the bounty, that won't work - read the FAQ. You will also lose the ability to accept an answer for this question. – Hugh Allen – 2010-05-30T08:22:35.470

I don't need any points. :) I need the feature in my VS! And don't worry. It's enough time to try and give you the bounty. :) – Vasyl Boroviak – 2010-05-30T11:22:55.523

MessageBox requires some parameters. I dunno what should I write there. Also what should I #include in order to get thread ID? Please, provide code in order to get this thing done. – Vasyl Boroviak – 2010-05-31T06:23:03.287

False alarm! I googled all the code I need. The result is following. MessageBox shows Thread ID : 2724. The devenv.exe PID is the same 2724. :( Also my VS2008 got crazy! The message box is being showed in endless loop. Probably the OnConnection is no the best place to show message boxes. – Vasyl Boroviak – 2010-05-31T06:39:03.347

@Vasiliy Borovyak: "Probably the OnConnection is no the best place to show message boxes". I agree. You should really use OutputDebugString(), but in order to see its output you'll need either a debugger attached to VS (eg. a second instance of VS), or use Sysinternals' DebugView: http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

– Hugh Allen – 2010-05-31T08:31:06.930

@Vasiliy Borovyak: "Thread ID : 2724. The devenv.exe PID is the same 2724" That seems like way too much of a coincidence. Are you sure that TID == PID?? And have you used Spy++ to find out the TID which owns the main editor window? (Note: VS's TIDs and PIDs will be different each time you start it up - I just want to know if the TID which calls OnConnection is the one which owns the GUI) – Hugh Allen – 2010-05-31T08:34:19.310

You are correct. I used getpid() function. Thus I changed to call the GetCurrentThreadId(), and it shows 2200. Using Spy++ on editor showed 0x898 (which is same 2200). So the thread is the same. – Vasyl Boroviak – 2010-05-31T10:28:29.023

@Vasiliy Borovyak: In that case I don't know why it doesn't work for you. I can't test / debug it myself because I have VS2003 on XP 32-bit and it works for me. Maybe instead you could find a way to unload msctf.dll (which implements the hotkey) from the VS process. Perhaps try the alpha 64-bit version of Unlocker: http://ccollomb.free.fr/unlocker/

– Hugh Allen – 2010-05-31T11:51:11.320

Unload a .dll out of VS? Seems nuts approach. :) I'm not going to do that because it is way too complicated. Thanks anyway. – Vasyl Boroviak – 2010-05-31T13:14:10.897

@Vasiliy Borovyak: Right. Unloading the DLL only crashes VS :) You could try calling SetProcessPreferredUILanguages, but it looks like it's for GUI languages not input languages. Also I can't write the code for you as I don't have Win7. Docs at http://msdn.microsoft.com/en-us/library/dd374050%28v=VS.85%29.aspx

– Hugh Allen – 2010-06-01T02:56:45.583