个人用excel比较多,自带的快捷键用的不太爽,用alt为主映射了一些自用的快捷键,发出来希望大家能指出一些不足,感谢.
大概键位参照一下图
部分代码用的ez老师的,函数用的飞跃大佬的
;仅在excel生效
#IfWinActive,ahk_class XLMAIN
{
;F功能区重新利用
f3::PostMessage, 0x111, 447, 0, , a
!l::
objExcel:=Excel_Get()
objExcel.Application.DisplayAlerts:= false
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.close
objExcel.Application.DisplayAlerts:= true
return
!j::send,!asa
!k::send,!asd
;没快捷键的常用功能,主要根据英文名改的
!s::Send,!ae
!q::
objExcel:=Excel_Get()
objExcel.Selection.Interior.ColorIndex := 6
return
!n::Send,!hhn
!e::Send,!hac
!y::Send,!hw
!t::send,!wff
!r::send,!ohr
;自行调整行高
![::
try{
ox := ComObjActive("Excel.Application")
ox.Application.Selection.EntireRow.AutoFit
}
catch e{
;出错就用传统快捷键
Send,!ora
}
return
;自行调整列宽
!]::
try{
ox := ComObjActive("Excel.Application")
ox.Application.Selection.EntireColumn.AutoFit
}
catch e{
Send,!oca
}
return
;复制单元格纯文本
!c:: send,{F2}^+{Home}^c{Esc}
!v::
Send {Blind}{LAlt Up}
; Clipboard:=""
; SendInput,^c
; Sleep 100
; MsgBox,4096,选中粘贴的位置,选中粘贴的位置
; Sleep 100
clipboard = %clipboard%
Sleep 100
send,{Blind}^v
return
!u::
objExcel:=Excel_Get()
InputBox,b,插入几行
loop % b
{
objExcel.ActiveCell.Offset(1, 0).EntireColumn.Insert
}
return
!i::
objExcel:=Excel_Get()
InputBox,b,插入几行
loop % b
{
objExcel.ActiveCell.Offset(1, 0).EntireRow.Insert
}
return
;选中和移动光标和切换工作表
!WheelUp::Send,{left 8}
!WheelDown::Send,{right 8}
+WheelUp::Send,{Left}
+WheelDown::Send,{Right}
!Right::SendInput,^{PgDn}
!Left::SendInput,^{PgUp}
;函数快速输入
^+v::
SendInput,{Text}=VLOOKUP()
SendInput +{F3}
return
}
#IfWinActive,ahk_class SoPY_Comp
{
F10::
MsgBox,aaaa
return
}
;======== 下面是函数 ========
;-- 将对象数据写入记录文件,记录文件在AHK主程序目录中
WriteLog(arr)
{
static f:=A_AhkPath . "\..\操作记录.txt"
s:=""
For k,v in arr
s.=A_Index=1 ? v : A_Tab . v
s:=A_Now . A_Tab . StrReplace(s,"`r") . "`n"
FileAppend, %s%, %f%
}
;-- 获取Excel窗口的COM对象 By FeiYue
Excel_Get(WinTitle="ahk_class XLMAIN")
{
static obj
Try
if (obj.Version)
return obj
return obj:=Office_Get(WinTitle)
}
;-- 获取所有Office窗口的COM对象 By FeiYue
Office_Get(WinTitle="")
{
static h:=DllCall("LoadLibrary", "Str","oleacc", "Ptr")
WinGet, list, ControlListHwnd, % WinTitle ? WinTitle : "A"
For i,hWnd in StrSplit(list, "`n")
{
ControlGetPos, x, y, w, h,, ahk_id %hWnd%
if (y<10 or w<100 or h<100)
continue
if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd
, "UInt", 0xFFFFFFF0, "Ptr", 0*(VarSetCapacity(IID,16)
+NumPut(0x0000000000020400,IID,"Int64")
+NumPut(0x46000000000000C0,IID,8,"Int64"))+&IID, "Ptr*", pacc)=0
{
Acc:=ComObject(9, pacc, 1)
Try
if (Acc.Application.Version)
return Acc.Application
}
}
MsgBox, 4096,, Error: Can't Get Object From ACC !
Exit
}