PDA

View Full Version : Lập trình lại bàn phím với AutoHotkey. Thay đổi chức năng của bàn phím cảm ứng trên laptop.



warpzv
06-05-2009, 11:55
Bạn đã bao giờ muốn thay đổi hay gán chức năng cho các phím trên bàn phím để có thể thao tác nhanh hơn.
Bạn muốn thay đổi chức năng của những phím mặc định.
Một ví dụ cơ bản: Bạn có laptop HP (dòng dv), bạn có để ý thấy trên dãy phím cảm ứng có 2 phím là Quickplay và DVD. Bạn có bao giờ sử dụng chúng không?
Tôi không bao giờ dùng chúng cả. Xem phim, hay mở DVD có những chương trình chuyên dụng tốt hơn QuickPlay nhiều. Và, bạn có thể làm gì?
Tôi đã chuyển phím QuickPlay thành phím mở chương trình nghe nhạc MediaMonkey, phím DVD thành phím mở My Computer.
Nếu muốn biết kỹ hơn, bạn có thể tham khảo trong tài liệu Help đi kèm phần mềm. Ở đó hướng dẫn rất đầy đủ. Chỉ cần một chút thời gian là bạn có thể bắt bàn phím làm việc theo ý mình. Rất đơn giản phải không.
Đây là file mình tạo, nó có một số chức năng:
- Đóng cửa sổ hiện hành bằng phím tắt Win+ESC
- Thu nhỏ cửa sổ hiện hành: Win+`
- Thu cửa sổ về còn thanh tiêu đề/Phục hồi bằng phím Win+Z
- Di chuyển một cửa sổ bằng cách nhấn Alt cùng với Click chuột trái ở bất cứ đâu trong vùng hiển thị của cửa sổ (không còn giới hạn ở thanh tiêu đề nữa)
- Set on Top đối với một cửa sổ: Win + 6 (^) (thường dùng khi nhập key một phần mềm...)
- Nếu gặp vấn đề xung đột sử dụng tổ hợp phím Ctrl + Alt + S để tạm ngừng chương trình
- Reload lại chương trình bằng tổ hợp Ctrl + Alt + R


Tải AutoHotKey về tại: http://www.autohotkey.com/download/A...keyInstall.exe
Copy đoạn mã sau vào notepad và save với tên bạn muốn và phần mở rộng là ahk







;Cac ban co the thay tham so cho phu hop
;
;
;
;
;
;
;
;
; Thu cua so ve thanh tieu de voi Win+Z
;

#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.


; Set the height of a rolled up window here. The operating system
; probably won't allow the title bar to be hidden regardless of
; how low this number is:
ws_MinHeight = 25

; This line will unroll any rolled up windows if the script exits
; for any reason:
OnExit, ExitSub
return ; End of auto-execute section

#z:: ; Change this line to pick a different hotkey.
; Below this point, no changes should be made unless you want to
; alter the script's basic functionality.
; Uncomment this next line if this subroutine is to be converted
; into a custom menu item rather than a hotkey. The delay allows
; the active window that was deactivated by the displayed menu to
; become active again:
;Sleep, 200
WinGet, ws_ID, ID, A
Loop, Parse, ws_IDList, |
{
IfEqual, A_LoopField, %ws_ID%
{
; Match found, so this window should be restored (unrolled):
StringTrimRight, ws_Height, ws_Window%ws_ID%, 0
WinMove, ahk_id %ws_ID%,,,,, %ws_Height%
StringReplace, ws_IDList, ws_IDList, |%ws_ID%
return
}
}
WinGetPos,,,, ws_Height, A
ws_Window%ws_ID% = %ws_Height%
WinMove, ahk_id %ws_ID%,,,,, %ws_MinHeight%
ws_IDList = %ws_IDList%|%ws_ID%
return

ExitSub:
Loop, Parse, ws_IDList, |
{
if A_LoopField = ; First field in list is normally blank.
continue ; So skip it.
StringTrimRight, ws_Height, ws_Window%A_LoopField%, 0
WinMove, ahk_id %A_LoopField%,,,,, %ws_Height%
}
return
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++

;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++
;-------------------------------------------------------------------------------
;Set On Top voi phim Win + 6 (^)

#6::WinSet, AlwaysOnTop, Toggle, A


;-----------------------------------------------------------------------------
;Tuy chinh phim Quick Play va DVD tren day phim cam ung
;Phim QuickPlay, thay doan sau Run bang duong dan den chuong trinh ban muon chay
sc108::Run "C:\Program Files (x86)\MediaMonkey\MediaMonkey.exe" /NoSplash

;Phim DVD
sc10E::Run %windir%\explorer.exe

;-------------------------------------------------------------------------------

;-------------------------------------------------------------------------------
;Thu nho va dong cua so
#`::WinMinimize, A

#Esc::WinClose, A

;-------------------------------------------------------------------------------
^!R::Reload
^!S::Suspend
;-----------------------------------------------------------------------------


;----------------------------------------------------------




LAlt & LButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return

EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_Mou***, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_Mou*** - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_Mou*** ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return


;--------------------------------------------------------














Nếu muốn chương trình chạy khởi động cùng hệ thống thì copy file .ahk bạn tạo vào thư mục Startup ở Start menu (Hình như ở: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup) (Nhấn phải chuột lên thư mục Startup chọn Explorer All Users)
Edit/Delete Message