ahk hotkey个人资料

时间:2013-03-01 20:50:27

标签: excel excel-vba scripting autohotkey key-bindings vba

以下是我的工作代码,以防其他人帮助!

#Warn  ; Enable warnings to assist with detecting common errors.
#SingleInstance FORCE

GUI, Add, Radio, vInventoryCompare, Compare Inventories
GUI, Add, Radio, vProductionSheet, Production Spreadsheet Stuff
GUI, Add, Radio, vInventorySheet, Inventory Sheet Stuff
GUI, Add, Radio, vStop, Disable Hotkeys
GUI, Add, Button, default xm, Set  ; xm puts it at the bottom left corner.
GUI, Show

ButtonSet:
GUI, Submit, NoHide
Return




Insert:: ; paste values
send, {alt}hvv
return

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

Home::
If InventoryCompare = 1 ; font size up 3 times
{
Send, {enter}{up}
Loop 3
{
Send, {alt}hfg
}
return
}
Else If ProductionSheet = 1 ; Recheck
{
Send, {enter}{up}
Send, {alt}hfc{down 7}{right 3}{enter}
Send, {F2}{left 5}
Send, R-{enter}{up}
return
}
Else If Stop = 1
{
send {Home}
Return
}
Return

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

End::
If InventoryCompare = 1 ; autocounter for bcg
{
Sendraw, =SUMIF($A$8:$A$38,A3,$F$8:$F$38)
send {enter}
return
}
Else If ProductionSheet = 1 ; discard
{
Send, D{enter}{up}
Send, ^b
return
}
Else If InventorySheet = 1 ; write ok+ and tab
{
send {tab}
Sendraw, ok+
send {tab}
return
}
Else If Stop = 1
{
send {end}
Return
}
Return

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

PgUp::
If InventoryCompare = 1 ; green bg with white text
{
Send, {alt}hh{down 6}{right 5}{enter} ; bg green
Send, {alt}hfc{down}{left 4}{enter} ; font white
return
}
Else If ProductionSheet = 1 ; ok+ coloring
{
Send, {enter}{up}
Send, {alt}hfc{down 7}{right}{enter}
return
}
Else If InventorySheet = 1 ; write ok and tab
{
send {tab}
Sendraw, ok
send {tab}
return
}
Else If Stop = 1
{
send {PgUp}
Return
}
Return

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

PgDn:: 
If  InventoryCompare = 1 ; red bg with white text
{
Send, {alt}hh{down 6}{right}{enter} ; bg red
Send, {alt}hfc{down}{left 4}{enter} ; font white
return
}
Else If ProductionSheet = 1 ; ok- coloring
{
Send, {enter}{up}
Send, {alt}hfc{down 7}{left 3}{enter}
return
}
Else If InventorySheet = 1 ; write ok- and tab
{
send {tab}
Sendraw, ok-
send {tab}
return
}
Else If Stop = 1
{
send {PgDn}
Return
}
Return

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

PrintScreen::
If InventoryCompare = 1 ; Break merged top cell of old inventories
{
send {F2} ; enter cell
sleep 200
send +{left 50} ; select name
sleep 200
send ^x ; cut name
sleep 200
send {enter}{up} ; reselect cell
sleep 200
send {alt}hmu ; break merged cells
sleep 200
send {down}{f2}^v{enter} ; paste name
return
}
Else If Stop = 1
{
send {PrintScreen}
Return
}
Return


GuiClose:
ExitApp

老问题: 我有3组keybind宏,我想使用带有单选按钮(或其他一些方法)的GUI合并到一个脚本中,以选择当前活动的热键集。不幸的是,每次运行脚本时,我都会收到“重复热键”错误(如果它告诉你什么的话,在End键上)。

我一直在网上试图找到有人尝试同样的事情,但我什么也没想到。我是在正确的轨道上吗?它甚至可能吗?

谢谢你的时间!

GUI, Add, Radio, vInventoryCompare, Compare Inventories
GUI, Add, Radio, vProductionSheet, Production Spreadsheet Stuff
GUI, Add, Radio, vInventorySheet, Inventory Sheet Stuff
GUI, Add, Radio, vDisable, Disable hotkeys
GUI, Show

GuiClose:
ExitApp

IF ErrorLevel
ExitApp

Insert:: ; paste values
send, {alt}hvv
return

IF %vInventoryCompare% = 1
{
End:: ; autocounter for bcg
Sendraw, =SUMIF($A$8:$A$38,A3,$F$8:$F$38)
send {enter}
return

Home:: ; font size up 3 times
Send, {enter}{up}
Loop 3
{
Send, {alt}hfg
}
return

PgUp:: ; green bg with white text
Send, {alt}hh{down 6}{right 5}{enter} ; bg green
Send, {alt}hfc{down}{left 4}{enter} ; font white
return

PgDn:: ; red bg with white text
Send, {alt}hh{down 6}{right}{enter} ; bg red
Send, {alt}hfc{down}{left 4}{enter} ; font white
return

PrintScreen:: ; Break merged top cell of old inventories
send {F2} ; enter cell
sleep 200
send +{left 50} ; select name
sleep 200
send ^x ; cut name
sleep 200
send {enter}{up} ; reselect cell
sleep 200
send {alt}hmu ; break merged cells
sleep 200
send {down}{f2}^v{enter} ; paste name
return

}

IF %vProductionSheet% = 1
{
End:: ; discard
Send, D{enter}{up}
Send, ^b
return

Home:: ; Recheck
Send, {enter}{up}
Send, {alt}hfc{down 7}{right 3}{enter}
Send, {F2}{left 5}
Send, R-{enter}{up}
return

PgUp:: ; ok plus coloring
Send, {enter}{up}
Send, {alt}hfc{down 7}{right}{enter}
return

PgDn:: ; ok minus coloring
Send, {enter}{up}
Send, {alt}hfc{down 7}{left 3}{enter}
return
}

IF %vInventorySheet% = 1
{
End::
send {tab}
Sendraw, ok+
send {tab}
return

PgUp::
send {tab}
Sendraw, ok
send {tab}
return

PgDn::
send {tab}
Sendraw, ok-
send {tab}
return
}

IF %vDisable% = 1
{
}

2 个答案:

答案 0 :(得分:0)

您无法以天真的方式多次定义相同的热键,唯一的方法就是使用#IfWinActive

我建议不要制作多个热键和多个if语句,而是制作一个热键并将所有if语句放入其中。

hotkey::
    if(statement)
    {
        do this;
    }
    else if(statement)
    {
        do that;
    }
    else...
return

答案 1 :(得分:0)

我知道您已经找到了答案,但如果您使用AutoHotKey_L,则可以使用#IF
#IF的作用类似于#IfWindowActive,但随后是常规的if语句 在这里你可以创建一个像:

这样的脚本
#IF (vInventoryCompare = 1)
    Home::
        Send....
        .
        .
    Return
#IF (vProductionSheet = 1)
    Home::
        Send....
        .
        .
    Return
#IF

P.S。如果你想发送OK +,你可以使用SendRaw,但你也可以使用常规发送。在这里你可以写:发送,OK + =
+移动下一个字符。 Shift + = +