5

I have two languages set in my windows settings - Czech (default) and English (for programming). I want to switch between them in powershell.

I generally work in Czech language, and it is my default language on my PC. So whenever I (re)start any app, it starts with Czech keyboard layout.

But I am programming with English layout. So I always need to tap Alt+Shift when I am starting new programming app - i.e. powershell window.

Is there some way to do this with some command in powershell? Or in C#, possibly through some win32 api call (as I could make myself small cmdlet for this)?

I found this question (and some others), but I didn't understand it(them) much...

I never worked with Win API, so I don't know what exactly is possible and how to work with it...

Does somebody has some cmdlet or little tutorial how to do this?

Community
  • 1
  • 1
jumbo
  • 4,670
  • 5
  • 39
  • 44
  • Well, you could wrap the API calls into a C# class you add with `Add-Type`. Not pretty but should work somehow. – Joey Apr 19 '12 at 20:24
  • Yes, that is on my mind. But I never programmed WinAPI, so I thought somebody could help me with few lines of code. – jumbo Apr 19 '12 at 20:28
  • `ActivateKeyboardLayout` is what you are looking for ... http://msdn.microsoft.com/en-us/library/windows/desktop/ms646289(v=vs.85).aspx ... but whether that works in a console window, where the idea of what is a process and what's just a thread is not always well distinguishable is unclear to me. – 0xC0000022L Apr 19 '12 at 21:07
  • That looks promising. Thanks, that is great for start. I will search this in evening. – jumbo Apr 20 '12 at 05:09
  • I just tried ActivateKeyboardLayout function. It works in WinForms, but it doesn't in console app. (I am testing in c#). Any thoughts on why console app behaves differently? – jumbo Apr 21 '12 at 23:29

2 Answers2

0

I found nice and very easy solution! There is WASP project on Codeplex. This project allows to manipulate windows, send keys to them and send clicks to them.

Solution for my problem is to import the WASP module when powershell is starting, then select powershell window (using WASP) and send Alt+Shift keystroke to it (using WASP).

Here is the code to include to the powershell profile.ps1 file in order to change language to the next one:

Import-Module WASP
Select-Window powershell | Send-Keys "%+" # '%' = ALT key, '+' = SHIFT key
jumbo
  • 4,670
  • 5
  • 39
  • 44
-5

Go to the Control Panel, open Regional and Language Options.

Click the Details...

Click Add and Remove to manage the languages you need.

add your language. Click OK to exit.

The keyboard layout is changed, you can switch them via Language Bar.

you can also check this link:

http://krypted.com/commands/powershell-commands/

Elnaz
  • 1,095
  • 1
  • 12
  • 30
  • 1
    Well, i didn't ask for windows settings. I am not so stupid (although, maybe my English is). I asked for powershell function that does the switching. I also know where to find the list of PS commands. None of them is named Switch-KeyboardLayout... – jumbo Apr 19 '12 at 20:18