AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Keyboard remap Bug help (again)

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
lbrtdy



Joined: 13 Apr 2009
Posts: 101

PostPosted: Wed Jan 20, 2010 3:44 am    Post subject: Keyboard remap Bug help (again) Reply with quote

Hello Ahk forums again.

A long long time ago, I came to you on how to write a script that remaps the QWERTY keyboard layout to Dvorak except when the modifiers win, ctrl, or alt is held down. Which suspended the remap and used the default QWERTY. Also scroll lock light on = QWERTY off = Dvorak. The script is as follows:

Code:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#MaxHotkeysPerInterval 999
;----------------------------------------------------------------------------------------
Menu, Tray, Icon, main.cpl, 8
SetScrollLockState, off

~*ScrollLock::
Suspend, Permit
ScrollState := GetKeyState("ScrollLock", "T") ? "On" : "Off"
Suspend, %ScrollState%
Hotkey, *Ctrl, toggle
Hotkey, *Ctrl up, toggle
Hotkey, *Alt, toggle
Hotkey, *Alt up, toggle
Hotkey, *LWin, toggle
Hotkey, *LWin up, toggle
Hotkey, *Rwin, toggle
Hotkey, *Rwin up, toggle
return

;----- Release keys from remap when modifier is 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

*RWin::
SetKeyDelay -1
Send {Blind}{RWin DownTemp}
Suspend on
Return
*RWin Up::
Suspend off
SetKeyDelay -1
Send {Blind}{RWin Up}
Return

;----------- 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


The above script the keyboard is kept at QWERTY and then using the script is switched to Dvorak. I need help making a script that does essentially the opposite. Instead of the OS using QWERTY as a default and using ahk to remap, the OS will use Dvorak as default, and ahk will suspend the remap until win, ctrl, or alt is held down. And when such keys are held down, it'll remap the Dvorak to QWERTY.

The reason why I'm wanting to remake the script is because my typing speed is getting faster and ahk is not very reliable at remapping at higher speeds. Often it would fail a remap, so I'm hoping this way, letting the OS handle the speeds unless I need to cut copy or paste would be more reliable.

Here is the hardest part and I've done it.. the correlation between which key remaps to which:

Code:

[::-
]::=

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

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

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


Also, as with the original script, scroll lock light Off = dvorak (remap always off unless modifiers are held down), Scroll lock light on = QWERTY (remap always on regardless if modifiers held down or not)

Problems I had trying to do this:
--The scroll lock light is opposite, off = qwerty on = dvorak
--Pushing and releasing modifier breaks the sync between light on/off correlates to which layout.

My failed script attempt:
Code:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#MaxHotkeysPerInterval 999
;----------------------------------------------------------------------------------------
Menu, Tray, Icon, main.cpl, 8
SetScrollLockState, off

~*ScrollLock::
Suspend, Permit
ScrollState := GetKeyState("ScrollLock", "T") ? "On" : "Off"
Suspend, %ScrollState%
Hotkey, *Ctrl, toggle
Hotkey, *Ctrl up, toggle
Hotkey, *Alt, toggle
Hotkey, *Alt up, toggle
Hotkey, *LWin, toggle
Hotkey, *LWin up, toggle
Hotkey, *Rwin, toggle
Hotkey, *Rwin up, toggle
return

;----- Release keys from remap when modifier is down-----
~*Ctrl::
SetKeyDelay -1
Send {Blind}{Ctrl DownTemp}
Suspend Off
return
~*Ctrl up::
Suspend On
SetKeyDelay -1
Send {Blind}{Ctrl Up}
return

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

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

*RWin::
SetKeyDelay -1
Send {Blind}{RWin DownTemp}
Suspend Off
Return
*RWin Up::
Suspend On
SetKeyDelay -1
Send {Blind}{RWin Up}
Return

;----------- REMAP FROM QWERTY TO DVORAK------------

[::-
]::=

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

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

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



Hopefully with the help of you guys, things will go well.
Thank you all,
-albert


Last edited by lbrtdy on Thu Jan 21, 2010 7:29 am; edited 3 times in total
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Wed Jan 20, 2010 11:04 am    Post subject: Reply with quote

It is a little tricky to do that this way, the problem is when you suspend your script, your ScrollLock hotkey and all the others are disabled so you cannot use it.
The only way to override that, is to use Suspend command for a Hotkey in first line.
Hope this will give you some idea how to get it working:
EDIT: pressing LWin or RWin only will still call up StartMenu.
Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetKeyDelay -1
;----------------------------------------------------------------------------------------
Menu, Tray, Icon, main.cpl, 8
SetScrollLockState, off

~ScrollLock::Suspend % GetKeyState("ScrollLock","T") ? "On" : "Off"

;----- Release keys from remap when modifier is down-----
$LWin::Suspend
$LWin Up::Suspend % Send("{LWin}")
$RWin::Suspend
$RWin Up::Suspend % Send("{LWin}")
;----------- REMAP FROM QWERTY TO DVORAK------------
Send(key){
   If (SubStr(A_PriorHotkey,-2)!="Win")
      Send % key
}

[::-
]::=

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

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

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

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
lbrtdy



Joined: 13 Apr 2009
Posts: 101

PostPosted: Thu Jan 21, 2010 2:50 am    Post subject: Reply with quote

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Play ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#MaxHotkeysPerInterval 999
;----------------------------------------------------------------------------------------
Menu, Tray, Icon, main.cpl, 8
SetScrollLockState, off
Suspend, On

~*ScrollLock::
Suspend, Permit
ScrollState := GetKeyState("ScrollLock", "T") ? "Off" : "On"
Suspend, %ScrollState%
Hotkey, *Ctrl, toggle
Hotkey, *Ctrl up, toggle
Hotkey, *Alt, toggle
Hotkey, *Alt up, toggle
Hotkey, *LWin, toggle
Hotkey, *LWin up, toggle
Hotkey, *Rwin, toggle
Hotkey, *Rwin up, toggle
return

;----- Release keys from remap when modifier is down-----
~*Ctrl::
Suspend, Permit
SetKeyDelay -1
Send {Blind}{Ctrl DownTemp}
Suspend Off
return
~*Ctrl up::
Suspend, Permit
Suspend On
SetKeyDelay -1
Send {Blind}{Ctrl Up}
return

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

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

*RWin::
Suspend, Permit
SetKeyDelay -1
Send {Blind}{RWin DownTemp}
Suspend Off
Return
*RWin Up::
Suspend, Permit
Suspend On
SetKeyDelay -1
Send {Blind}{RWin Up}
Return

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

[::-
]::=

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

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

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


I tried your example, but I couldn't figure how. However, I did manage to get mine working. I just had to add Suspend, permit to the hotkeys and then switch the suspend on and off around for each hotkey. So thank your for your help! Your got me in the right direction, I didn't even think that the hotkeys were being suspended lol, no wonder why they wouldn't work >.> Thanks!
-albert
Back to top
View user's profile Send private message
lbrtdy



Joined: 13 Apr 2009
Posts: 101

PostPosted: Thu Jan 21, 2010 7:18 am    Post subject: Reply with quote

Ok after fixing the problems, I ran into some minor bugs again Sad
This is currently what I have:

Code:
#SingleInstance, force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Play ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#MaxHotkeysPerInterval 999
;----------------------------------------------------------------------------------------
Menu, Tray, Icon, main.cpl, 8
SetScrollLockState, off
Suspend, On

~*ScrollLock::
Suspend, Permit
ScrollState := GetKeyState("ScrollLock", "T") ? "Off" : "On"
Suspend, %ScrollState%
Hotkey, *Ctrl, toggle
Hotkey, *Ctrl up, toggle
Hotkey, *Alt, toggle
Hotkey, *Alt up, toggle
;~ Hotkey, *LWin, toggle
;~ Hotkey, *LWin up, toggle
;~ Hotkey, *Rwin, toggle
;~ Hotkey, *Rwin up, toggle
return

;----- Release keys from remap when modifier is down-----
~*Ctrl::
Suspend, Permit
SetKeyDelay -1
Send {Blind}{Ctrl DownTemp}
Suspend Off
return
~*Ctrl up::
Suspend, Permit
SetKeyDelay -1
Send {Blind}{Ctrl Up}
Suspend On
return

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

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

;~ *RWin::
;~ Suspend, Permit
;~ SetKeyDelay -1
;~ Send {Blind}{RWin DownTemp}
;~ Suspend Off
;~ Return
;~ *RWin Up::
;~ Suspend, Permit
;~ Suspend On
;~ SetKeyDelay -1
;~ Send {Blind}{RWin Up}
;~ Return


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

[::-
]::=

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

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

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



Bugs:
--ScrollLock light doesn't automatically shut off when the script is run despite the
Code:
SetScrollLockState, off
So if it is run with light on, On = dvorak, toggle, off = dvorak, toggle, on = QWERTY and everything goes good from there.
--When ScrollLock light on = QWERTY (suspend off, remapping). If you type something and do Control + a, it selects all the text just fine, but when you do control + c without letting go of the control, it sometimes replaces the text and puts a "c" there like control isn't held down at all. Even releasing control doesn't work, you have to put focus on something else and then back on window to be able to copy without replacing selected text with "c".
--When ScrollLock light on = QWERTY (suspend off, remapping) and you do say shift A in the word Ahk, it gets delayed one key so it becomes aHk.

Currently these are all the bugs I found. I'm trying to work some of them out, and any help would be appreciated. Thanks! -albert Smile
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Thu Jan 21, 2010 3:58 pm    Post subject: Reply with quote

Quote:
I tried your example, but I couldn't figure how

In my example only LWin + RWin work as well as ScrollLock, I am not sure if you could do it different way.
Give it a try again.
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group