* post นี้ยกเลิก โปรดดูอีก post หนึ่ง **

* post นี้ยกเลิก โปรดดูอีก post หนึ่ง **

AutoHotKey setting กรณีสลับปุ่ม Windows กับ Alt

ปัญหาคืออยากใช้ปุ่ม alt+spacebar ในการสลับภาษาให้เหมือนๆ กันระหว่าง Windows กับ Mac

ซึ่งใน Windows พยายามใช้ AutoHotkey แปลงปุ่ม alt+spacebar เป็น alt-shift แล้ว แต่มันใช้กับ Microsoft Office ไม่ได้ ก็เลยใช้วิธีใหม่ ใช้ win+spacebar แทน โดยสลับปุ่ม win เป็น alt ด้วย SharpKeys เลย ได้ผลดี คือ ตอบสนองไว ใช้ได้ทุกโปรแกรม แต่ปัญหาที่ตามมาก็คือ ต้อง ปรับ short cut อื่นๆ ที่เคยใช้กับ alt ให้มาใช้กับ win ตามในข้อ 2

สรุปขั้นตอน
1. ใช้ SharpKeys สลับปุ่ม Alt กับ Windows (แก้ registry)

2. AutoHotKey setting for Windows

#q::Send, !{F4}
#a::Send, ^a
#c::Send, ^c
#v::Send, ^v
::Send, ^t
#x::Send, ^x
#w::Send, ^w
#z::Send, ^z
#y::Send, ^y

;#m::Send, +{#} ; minimize all
;#u::Send, +{#}m ; unminimize

!s:: Send, #s
!e:: Send, #e
!r:: Send, #r

!m:: WinMinimizeAll

LWin & Tab::AltTab
LWin & Left:: Send !{Left}
LWin & Right:: Send !{Right}

#f4::WinClose, A ; Win+C

#`:: ; Next window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
Return
Else
WinGet, List, List, % “ahk_class ” ActiveClass
Loop, % List
{
index := List – A_Index + 1
WinGet, State, MinMax, % “ahk_id ” List%index%
if (State -1)
{
WinID := List%index%
break
}
}
WinActivate, % “ahk_id ” WinID
return

#^`:: ; Last window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
Return
Else
WinGet, List, List, % “ahk_class ” ActiveClass
Loop, % List
{
index := List – A_Index + 1
WinGet, State, MinMax, % “ahk_id ” List%index%
if (State -1)
{
WinID := List%index%
break
}
}
WinActivate, % “ahk_id ” WinID
return

AutoHotKey setting กรณีสลับปุ่ม Windows กับ Alt

AutoHotKey setting กรณีสลับปุ่ม Windows กับ Alt

ใช้ Mac มานานๆ ก็เกิดความถนัด key binding ต่างๆ ของ Mac มาพอใช้ Windows ก็เลยอยากได้แบบของ Mac รวมถึงพวกปุ่มเปลี่ยนภาษาที่ใช้ alt-space

วิธีการใช้ Auto Hot Key และใส่เนื้อหา script ดังนี้

(script บางส่วนจาก https://superuser.com/questions/435602/shortcut-in-windows-7-to-switch-between-same-applications-windows-like-cmd)

พบว่าเปลี่ยนภาษาใช้วิธีนี้ดีที่สุด

LAlt & Space:: ; Change language
PostMessage, 0x50, 0x02,0,, A
Send, {Ctrl down}{Shift}{Ctrl up}
return

ที่ต้องเพิ่ม Send, {Ctrl down}{Shift}{Ctrl up} เพราะถ้าไม่มีบรรทัดนี้ พอใช้ร่วมกับ VcXsrv ซึ่งต้อง start ด้วย option
“C:Program FilesVcXsrvvcxsrv.exe” :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl -xkblayout us,th -xkbvariant winkeys -xkboptions grp:alt_shift_toggle

ปรากฎว่ามันจะไม่เปลี่ยนภาษาด้วย alt-space (แต่เปลี่ยนด้วย laft + lshift) แต่ถ้าใส่
Send, {Ctrl down}{Shift}{Ctrl up} แล้วมันทำให้เปลี่ยนภาษาด้วย alt-space ได้ ซึ่งได้เพราะอะไรยังงงๆ

# ปล. ในกรณีที่ใช้ Windows ใน VMWare Fusion ที่มีการสลับปุ่ม Option กับ Command (เพราะผมชอบให้ปุ่ม Alt (ซึ่งจะ mapped กับปุ่ม command) มันติดกับ spacebar) ก็ต้องเปลี่ยนเป็น

!Space:: ; Change language
PostMessage, 0x50, 0x02,0,, A
Send, {Ctrl down}{Shift}{Ctrl up}
return

#############################################
แบบอื่นๆ
;LAlt & Space:: PostMessage, 0x50, 0x02,0,, A

; แบบนี้ ใช้ได้กับทุกโปรแกรมยกเว้น Microsoft Office 😦
;!Space::
;Send, {ALTDOWN}{SHIFTDOWN}{SHIFTUP}{ALTUP}
;return
;!Space::Send, {Alt down}{Shift}{Alt up}

###############################################
# เนื้อหาไฟล์ที่ใช้ล่าสุด

!q::Send, !{F4}
!a::Send, ^a
!c::Send, ^c
!v::Send, ^v
!t::Send, ^t
!x::Send, ^x
!w::Send, ^w
!z::Send, ^z
!y::Send, ^y
!m::Send, +{#} ; minimize all
!u::Send, +{#}m ; unminimize

LAlt & Space:: PostMessage, 0x50, 0x02,0,, A

#c::Run calc.exe

!`:: ; Next window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
Return
Else
WinGet, List, List, % “ahk_class ” ActiveClass
Loop, % List
{
index := List – A_Index + 1
WinGet, State, MinMax, % “ahk_id ” List%index%
if (State -1)
{
WinID := List%index%
break
}
}
WinActivate, % “ahk_id ” WinID
return

!^`:: ; Last window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
Return
Else
WinGet, List, List, % “ahk_class ” ActiveClass
Loop, % List
{
index := List – A_Index + 1
WinGet, State, MinMax, % “ahk_id ” List%index%
if (State -1)
{
WinID := List%index%
break
}
}
WinActivate, % “ahk_id ” WinID
return