Jump to content


Photo

Mac Style Dvorak QWERTY Command Layout Switcher for Windows


  • Please log in to reply
35 replies to this topic

#1 arkenflame

arkenflame
  • Members
  • 5 posts

Posted 12 January 2008 - 08:24 PM

On Macs, there is a way to have the keyboard layout Dvorak when you type, but when you use a hotkey (by holding alt, ctrl, etc) it switches back to QWERTY so you don't have to remap all the shortcuts or have them in inconvenient places.

This script does just that. You can also toggle back to QWERTY by pressing the right windows key. I find this helpful for playing games etc.

Here is the script:

SendMode Input
#NoEnv
Menu, Tray, Icon, main.cpl, 8

;----------- REMAP TO DVORAK

-::[
=::]

q::'
w::,
e::.
r::p
t::y
y::f
u::g
i::c
o::r
p::l
[::/
]::=
;\::\ ;no change

;a::a ;no change
s::o
d::e
f::u
g::i
h::d
j::h
k::t
l::n
SC027::s
SC028::-

z::SC027
x::q
c::j
v::k
b::x
n::b
m::m
,::w
.::v
/::z


;----------- RELEASE KEYS FROM REMAP WHEN MODIFIER DOWN

*Ctrl::
SetKeyDelay -1
Send {Blind}{Ctrl DownTemp}
Suspend On
return
*Ctrl up::
Suspend Off
SetKeyDelay -1
Send {Blind}{Ctrl Up}
return

*Alt::
SetKeyDelay -1
Send {Blind}{Alt DownTemp}
Suspend On
return
*Alt up::
Suspend Off
SetKeyDelay -1
Send {Blind}{Alt Up}
return

*LWin::
SetKeyDelay -1
Send {Blind}{LWin DownTemp}
Suspend On
return
*LWin up::
Suspend Off
SetKeyDelay -1
Send {Blind}{LWin Up}
return

;----------- TOGGLE DVORAK-QWERTY WITH RIGHT WINDOWS KEY

*RWin::
Suspend, Permit
Suspend, toggle
Hotkey, *Ctrl, toggle
Hotkey, *Ctrl up, toggle
Hotkey, *Alt, toggle
Hotkey, *Alt up, toggle
Hotkey, *LWin, toggle
Hotkey, *LWin up, toggle
return

I also keep a (compiled) version of this on my flash drive that has a small gui allowing others to "fix" their keyboards by closing the window, in case I want to type on their computers and forget to switch it back myself.

Here is that version:

SendMode Input
#NoEnv

;----------- CREATE INFORMATION WINDOW
Menu, Tray, Icon, main.cpl, 8
Gui, Add, GroupBox, x2 y2 w326 h130 , Information
Gui, Add, Text, x10 y20 w300, Your keyboard layout has been temporarily changed. Close this window to restore your prior layout.
Gui, Add, Text, x10 y60 w300, If your keys aren't working right, or you are confused, press toggle or close this window.
Gui, Add, Text, x10 y100 w300, Current Layout: Dvorak
Gui, Add, Button, x20 y138 w90 h30  , Toggle 
Gui, Add, Button, x120 y138 w90 h30 , Minimize
Gui, Add, Button, x220 y138 w90 h30 , Close
Gui, Show, x552 y209 h175 w330, Dvorak Keyboard Layout Changer
Return

ButtonToggle:
Toggle()
Return

ButtonMinimize:
Gui, Show, Minimize
Return

GuiClose:
ButtonClose:
ExitApp

;----------- REMAP TO DVORAK

-::[
=::]

q::'
w::,
e::.
r::p
t::y
y::f
u::g
i::c
o::r
p::l
[::/
]::=
;\::\ ; no change

;a::a ; no change
s::o
d::e
f::u
g::i
h::d
j::h
k::t
l::n
SC027::s
SC028::-

z::SC027
x::q
c::j
v::k
b::x
n::b
;m::m ; no change
,::w
.::v
/::z


;----------- RELEASE KEYS FROM REMAP WHEN MODIFIER DOWN

*Ctrl::
SetKeyDelay -1
Send {Blind}{Ctrl DownTemp}
Suspend On
return
*Ctrl up::
Suspend Off
SetKeyDelay -1
Send {Blind}{Ctrl Up}
return

*Alt::
SetKeyDelay -1
Send {Blind}{Alt DownTemp}
Suspend On
return
*Alt up::
Suspend Off
SetKeyDelay -1
Send {Blind}{Alt Up}
return

*LWin::
SetKeyDelay -1
Send {Blind}{LWin DownTemp}
Suspend On
return
*LWin up::
Suspend Off
SetKeyDelay -1
Send {Blind}{LWin Up}
return

;----------- TOGGLE DVORAK-QWERTY WITH RIGHT WINDOWS KEY

*RWin::
Suspend, Permit
Toggle()
return

Toggle() {
Suspend, toggle
Hotkey, *Ctrl, toggle
Hotkey, *Ctrl up, toggle
Hotkey, *Alt, toggle
Hotkey, *Alt up, toggle
Hotkey, *LWin, toggle
Hotkey, *LWin up, toggle
if (A_IsSuspended = 1) {
GuiControl, Text, Static3, Current Layout: QWERTY (normal)
} else {
GuiControl, Text, Static3, Current Layout: Dvorak
}
return
}

I hope someone finds this as useful as I do. Enjoy!

#2 Jero3n

Jero3n
  • Members
  • 147 posts

Posted 12 January 2008 - 08:30 PM

Can ahk run on a mac?
Didn't knew that.

#3 arkenflame

arkenflame
  • Members
  • 5 posts

Posted 13 January 2008 - 10:20 PM

No no no. This is just a script that allows you to do something on Windows you can normally only do on a Mac.

#4 trik

trik
  • Members
  • 1317 posts

Posted 13 January 2008 - 10:24 PM

Alls it does is remap the keys. It does nothing to altar the windows processes.

#5 keybored

keybored
  • Members
  • 351 posts

Posted 17 January 2008 - 10:39 PM

arkenflame, Thank You so much! I couldn't figure out how to do this. I will be practicing Dvorak again.

#6 hatsat

hatsat
  • Guests

Posted 25 January 2008 - 06:29 AM

i've never played with the scripts before could you please post a link or explain in brief how to use the above script ... i saved it in notepad but don't know what to do next?

Anyways, thanks a million arkenflame !! i've been searching for an easy way to switch between qwerty and dvorak ... there is a constant fight between me (dvorak) and my qwerty loving siblings over the keyboard layout... i have to do atleast 2-3 times/day... control panel ...regional and language options ..languages ...details .. add ...dvorak ...and back again. thanks again

Btw is there a way to change the keyboard layout from qwerty to dvorak and vice versa with a simple command from cmd.exe in windows ...like qw=qwerty and dv=dvorak

#7 arkenflame

arkenflame
  • Members
  • 5 posts

Posted 31 January 2008 - 03:40 AM

hatsat, it's pretty easy.

Install AutoHotKey, right click on your dektop (or wherever) and select New > AutoHotKey Script, and name it what you want. Open it with notepad and paste in the code above. Then save it and double click on the file on your desktop. You can also right click on it and choose "Compile Script" if you want to run the (newly created) file without installing AutoHotKey elsewhere.

And just as a side note, my antivirus software (avast!) registers ahk-compiled programs as trojans, so you may need to add the program to an exception list.

#8 KayDat

KayDat
  • Members
  • 2 posts

Posted 19 February 2008 - 11:09 AM

What an excelent idea. I was just starting to do the same thing, but it looks like you beat me to it ;)

#9 Patulo

Patulo
  • Guests

Posted 19 April 2008 - 04:30 AM

Such a useful piece of code! I was using a Dvorak configuration before (with Windows Control Panel Regional Settings), but I had to memorize the new hotkeys and it wasn't easily customizable. Then I found this script and was pretty happy with it except for one problem: I can't use it with Jim Biancolo's AutoCorrect.ahk ( http://www.autohotke...AutoCorrect.ahk ). That script won't work properly when I use it simultaneously with this code. Anybody have a solution?

#10 Claes

Claes
  • Guests

Posted 08 May 2008 - 11:10 AM

I run in to a strange problem...

I tried the script and when I press "f" and get "g" when I expect "u". The circle reference is f::u u::g. What can I do to fix this?

#11 Jag02

Jag02
  • Members
  • 44 posts

Posted 11 May 2008 - 07:53 PM

Can this script be shortened?

#12 infogulch

infogulch
  • Moderators
  • 717 posts

Posted 12 May 2008 - 07:32 PM

You don't have to Add the keyboard layout every time, just switch it. In fact, I have a couple hotkeys to switch it between English and dvorak. Just go to "Text services and input languages" (See *), "[Button]Key Settings..." and set up some hotkeys to switch between the two layouts. (All within windows, btw) I have Windows use !+1 for regular layout, and !+2 for the dvorak, so if you have issues with other people using it, hit the hotkey to change it to dvorak, and when you're done, hit the hotkey to change it back.


*That's under "Control Panel>Reigonal and Language options>[Tab]Languages>[Button]Details". If you didn't have the new layout installed already, continue: "[Button]Add...>[CheckBox]Keyboard Layout". Then select the layout you want.

:D

#13 TheChaosMachine

TheChaosMachine
  • Guests

Posted 20 May 2008 - 07:04 PM

Hello,
This macro is awesome. It works exactly how I want it to, and is completely transparent.

There is 1 minor issue: I alt+tab very quickly. When I do so, the window that comes up which shows the icons of all running programs stays up. I found that if I hold ALT for about 1 second before hitting Tab, this problem does not happen.

I looked into the SetKeyDelay function, but at the -1 value it's set for already it is supposed to have 0 delay. Obviously there is a delay, and I can't figure out how to fix this. Does anyone know how to solve that issue?

Thanks!

#14 TheChaosMachine

TheChaosMachine
  • Guests

Posted 20 May 2008 - 08:41 PM

So I found a workaround. I mapped the following in the script, and it resolved the alt delay:

LAlt & `::AltTab
LAlt & ~::ShiftAltTab

Not sure why this worked, but if anyone else is running into the same problem, I would assume mapping Alt Tab to some other keypress would work the same way in case ` and ~ are used by other things.

#15 arkenflame

arkenflame
  • Members
  • 5 posts

Posted 29 May 2008 - 11:12 PM

I recently got a Logitech MX Revolution (very nice) and found that SetPoint (the logitech software) interfered with this ahk script. To work around this, I downloaded uberOptions from here http://www.mstar.net/users/rlowens/ and set my mouse buttons to keys F13-F<whatever> in SetPoint and then caught them in autohotkey to do what I wanted them to (like show desktop, aka Win+D).

If anyone else was having problems with this, I hope this helps. I still don't have any suggestions on fixing One-Touch Search though.

Thanks to this thread http://www.autohotke.../topic7695.html for the idea.