Does anyone know the API call I can use to change the keyboard layout on a windows machine to Dvorak? Doing it through the UI is easy but I'd like to have a script that I can run on new VM's to automate the process.
Answers
I just got my answer for my own question.
Just put nil
into inputView
and that will change back into English (US) Keyboard.
From the Control Panel select Language and then Options:
In the Input method select Add an input method:
From there you can select the DVORAK R or L keyboards
It seems that someone having the same problem worked around it using a Windows compiled Autohotkey script. It's a portable application you can bring with you on a thumbdrive, and you should be able to just plug it in and start it up whenever you log on, even with restricted access.
However, there isn't a layout for programmer dvorak, so you would have to create your own. I think this involves text editing the included Colemac layout. Why it doesn't use a standard layout format is beyond me.
But if you do make your own Programmer Dvorak layout for that program, please upload it here. People to follow will be happy to avoid this annoying journey.
Update
I've solved our problem! After a couple hours struggling with the sparse documentation for the excellent portable keyboard layout, I managed to cobble together a programmer dvorak configuration file. The image isn't correct, but most importantly typing works perfectly, and everything is where you expect it to be.
Installation Instructions
Fairly simple.
Download PKL and put it on a flash drive.
Download this layout.ini file -- Note, I'm going to paste this at bottom of post, since I guess you can't upload files on this site?
Replace "Portable Keyboard Layoutlayoutscolemaklayout.ini"
Start "Portable Keyboard Layoutpkl.exe" whenever you want to use Programmer Dvorak.
For the interested, I used the Microsoft Keyboard Layout Creator 1.4 and a klc2ini perl script (converts output of MSKLC to a format usable by PKL).
layout.ini file -- just paste this into the colemak layout.ini file, replacing everything in it.
Note: I'm not sure what the deadkey section is; the script produced a bunch of errors. But it works, so I'm not poking it.
EDIT: I've hosted the file here, as I've had trouble with copying the below text. Might be some formatting thing.
;
; Keyboard Layout definition for
; Portable Keyboard Layout
; http://pkl.sourceforge.net
;
[informations]
layoutname = United States-Dvorak-Programmer
layoutcode = DvrkProg
localeid = 00000409
copyright = Public Domain
company = Free
homepage = http://pkl.sourceforge.net/
version = 1.0
generated_from = DvrkProg.klc
modified_after_generate = no
[global]
; extend_key = CapsLock
shiftstates = 0:1:2
img_width = 296
img_height = 102
[fingers]
row1 = 1123445567888
row2 = 1123445567888
row3 = 1123445567888
row4 = 11234455678
[layout]
;scan = VK CapStat 0Norm 1Sh 2Ctrl Caps CapsSh
SC002 = 1 0 & % -- ; QWERTY 1!
SC003 = 2 0 [ 7 -- ; QWERTY 2@
SC004 = 3 0 { 5 -- ; QWERTY 3#
SC005 = 4 0 } 3 -- ; QWERTY 4$
SC006 = 5 0 ( 1 -- ; QWERTY 5%
SC007 = 6 0 = 9 -- ; QWERTY 6^
SC008 = 7 0 * 0 -- ; QWERTY 7&
SC009 = 8 0 ) 2 -- ; QWERTY 8*
SC00a = 9 0 + 4 -- ; QWERTY 9(
SC00b = 0 0 ] 6 -- ; QWERTY 0)
SC00c = OEM_4 0 ! 8 -- ; QWERTY -_
SC00d = OEM_6 0 # ` -- ; QWERTY =+
SC010 = OEM_7 0 ; : -- ; QWERTY qQ
SC011 = OEM_COMMA 0 , < -- ; QWERTY wW
SC012 = OEM_PERIOD 0 . > -- ; QWERTY eE
SC013 = P 1 p P -- ; QWERTY rR
SC014 = Y 1 y Y -- ; QWERTY tT
SC015 = F 1 f F -- ; QWERTY yY
SC016 = G 1 g G -- ; QWERTY uU
SC017 = C 1 c C -- ; QWERTY iI
SC018 = R 1 r R -- ; QWERTY oO
SC019 = L 1 l L -- ; QWERTY pP
SC01a = OEM_2 0 / ? -- ; QWERTY [{
SC01b = OEM_PLUS 0 @ ^ -- ; QWERTY ]}
SC01e = A 1 a A -- ; QWERTY aA
SC01f = O 1 o O -- ; QWERTY sS
SC020 = E 1 e E -- ; QWERTY dD
SC021 = U 1 u U -- ; QWERTY fF
SC022 = I 1 i I -- ; QWERTY gG
SC023 = D 1 d D -- ; QWERTY hH
SC024 = H 1 h H -- ; QWERTY jJ
SC025 = T 1 t T -- ; QWERTY kK
SC026 = N 1 n N -- ; QWERTY lL
SC027 = S 1 s S -- ; QWERTY ;:
SC028 = OEM_MINUS 0 - _ -- ; QWERTY '"
SC029 = OEM_3 0 $ ~ -- ; QWERTY `~
SC02b = OEM_5 0 | -- ; QWERTY |
SC02c = OEM_1 0 ' " -- ; QWERTY zZ
SC02d = Q 1 q Q -- ; QWERTY xX
SC02e = J 1 j J -- ; QWERTY cC
SC02f = K 1 k K -- ; QWERTY vV
SC030 = X 1 x X -- ; QWERTY bB
SC031 = B 1 b B -- ; QWERTY nN
SC032 = M 1 m M -- ; QWERTY mM
SC033 = W 1 w W -- ; QWERTY ,<
SC034 = V 1 v V -- ; QWERTY .>
SC035 = Z 1 z Z -- ; QWERTY /?
SC039 = SPACE 0 ={Space} ={Space} ={Space} ; QWERTY Space
SC056 = OEM_102 0 | ; QWERTY OEM_102
SC053 = DECIMAL 0 . . -- ; QWERTY Decimal in Numpad
[deadkey1]
0 = 0 ;
1 = 14 ; ->
14 = 2988 ; ->
15 = 0 ; ->
28 = 14 ; ->
29 = 12 ; ->
42 = 0 ; * ->
54 = 0 ; 6 ->
55 = 0 ; 7 ->
56 = 10 ; 8 ->
57 = 0 ; 9 ->
58 = 0 ; : ->
59 = 241 ; ; -> ñ
60 = 242 ; < -> ò
61 = 243 ; = -> ó
62 = 244 ; > -> ô
63 = 245 ; ? -> õ
64 = 246 ; @ -> ö
65 = 247 ; A -> ÷
66 = 248 ; B -> ø
67 = 249 ; C -> ù
68 = 3856 ; D -> ༐
69 = 0 ; E ->
70 = 0 ; F ->
71 = 0 ; G ->
72 = 0 ; H ->
73 = 0 ; I ->
74 = 0 ; J ->
75 = 0 ; K ->
76 = 0 ; L ->
77 = 0 ; M ->
78 = 0 ; N ->
79 = 0 ; O ->
80 = 0 ; P ->
81 = 0 ; Q ->
82 = 0 ; R ->
83 = 0 ; S ->
84 = 0 ; T ->
87 = 3857 ; W -> ༑
88 = 3858 ; X -> ༒
124 = 3859 ; | -> ༓
125 = 3860 ; } -> ༔
126 = 3861 ; ~ -> ༕
127 = 3862 ; -> ༖
128 = 3863 ; -> ༗
129 = 3864 ; -> ༘
130 = 3865 ; -> ༙
131 = 3872 ; -> ༠
132 = 3873 ; -> ༡
133 = 3874 ; -> ༢
134 = 3875 ; -> ༣
135 = 3876 ; -> ༤
This snippet did the trick for me. Note that I use Quicksilver to launch apps, so I remapped the keyboard shortcut for "switch input menu" from Cmd+Space
to Option+Cmd+S
.
osascript -e 'tell application "System Events"'
-e 'keystroke "s" using {command down, option down}'
-e 'end tell'
I may be four years late to the party, but did you ever find this:
Intlcfg Command-Line Options
I don't have Windows Vista (very bad habit, Windows), but looking at this page and also at Available Language Packs and Default Input Locales I reckon the command you want might well be:
for English (United States) language with United States Dvorak input locale.