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 

Avoid same hotkey in different hotkey control

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



Joined: 15 Mar 2008
Posts: 9

PostPosted: Tue Mar 18, 2008 6:34 pm    Post subject: Avoid same hotkey in different hotkey control Reply with quote

it's my first script, i use it in warcraft 3, there are 2 language in app, english and chinese (maybe GUI is full of unrecognizable characters, codepage936).
there are 6 hotkey controls in GUI, i have one problem, i would like to know how to avoid same hotkey in different hotkey control.
for example, there is alt+a in control1, if i input alt+a in control2, clear control1's hotkey and hotkey control will show "none"
i have read the help for this answer and can't find it...

is there any better solution for this?

thanks in advance
sorry for my english

Code:

#SingleInstance,Force
#NoTrayIcon
#Persistent
#NoEnv
#IfWinActive, ahk_class Warcraft III        ;// just run script in war3

SetBatchLines, -1

/*
########################
Global Settings
########################
*/

AppName = CustomItemKeys
Num7 = Numpad7
Num4 = Numpad4
Num1 = Numpad1
Num8 = Numpad8
Num5 = Numpad5
Num2 = Numpad2
StatusQ = Checked
StatusW = Checked
StatusT = Checked
StatusTray = Checked

;////////////////////////////////Set Control Label's Language, Chinese & English
GroupBox1TextCHS = 物品栏热键
GroupBox2TextCHS = 屏蔽选项
GroupBox3TextCHS = 其他选项
CheckQTextCHS = 屏蔽 Alt-Q
CheckWTextCHS = 屏蔽 WIN 键
CheckTTextCHS = 屏蔽 Alt-Tab
CheckTrayTextCHS = 最小化到托盘
BTNSubmitTextCHS = 启用
BTNSubmitText2CHS = 禁用
BTNSaveTextCHS = 保存
BTNExitTextCHS = 退出
MenuShowTextCHS = 显示

GroupBox1TextENG = Inventory Card
GroupBox2TextENG = Disable Option
GroupBox3TextENG = MISC.
CheckQTextENG = Disable Alt-Q
CheckWTextENG = Disable WIN
CheckTTextENG = Disable Alt-Tab
CheckTrayTextENG = Minimize to Tray
BTNSubmitTextENG = Start
BTNSubmitText2ENG = Stop
BTNSaveTextENG = Save
BTNExitTextENG = Exit
MenuShowTextENG = Show


Gosub, READCONF           ;//////////////////read config file
Gosub, GUIBEGIN
Return

/*
################################################################################
Create GUI, no trayicon, but when GUI hide, trayicon show and create tray menu
################################################################################
*/

GUIBEGIN:
Gui, Add, GroupBox, x11 y10 w230 h110 vGroupBox1, %GroupBox1TextCHS%
Gui, Add, Hotkey, x21 y30 w100 h20 vKeyNum7, %Num7%
Gui, Add, Hotkey, x21 y60 w100 h20 vKeyNum4, %Num4%
Gui, Add, Hotkey, x21 y90 w100 h20 vKeyNum1, %Num1%
Gui, Add, Hotkey, x131 y30 w100 h20 vKeyNum8, %Num8%
Gui, Add, Hotkey, x131 y60 w100 h20 vKeyNum5, %Num5%
Gui, Add, Hotkey, x131 y90 w100 h20 vKeyNum2, %Num2%
Gui, Add, GroupBox, x11 y130 w230 h90 vGroupBox2, %GroupBox2TextCHS%
Gui, Add, CheckBox, x21 y150 w100 h30 vCheckQ %StatusQ%, %CheckQTextCHS%
Gui, Add, CheckBox, x131 y150 w100 h30 vCheckW %StatusW%, %CheckWTextCHS%
Gui, Add, CheckBox, x21 y180 w150 h30 vCheckT %StatusT%, %CheckTTextCHS%
Gui, Add, GroupBox, x11 y230 w230 h60 vGroupBox3, %GroupBox3TextCHS%
Gui, Add, DropDownList, x131 y255 w98 h20 vDDLLang gDDLCHOICE R2 AltSubmit, 简体中文|English
Gui, Add, CheckBox, x21 y250 w110 h30 vCheckTray %StatusTray%, %CheckTrayTextCHS%
Gui, Add, Button, x11 y300 w70 h30 vBTNSubmit gBTNSUBMIT Default, %BTNSubmitTextCHS%
Gui, Add, Button, x91 y300 w70 h30 vBTNSave gSAVECONF Disabled, %BTNSaveTextCHS%
Gui, Add, Button, x171 y300 w70 h30 vBTNExit gGUICLOSE, %BTNExitTextCHS%
Gui, Show, h340 w250 Center, %AppName%
Return

;////////////////////////////////////////DropDownList, select language
DDLCHOICE:
Gui, Submit, NoHide
GuiControlGet, BTNSubmit
If ( DDLLang = 2 ){
   GuiControl,, GroupBox1, %GroupBox1TextENG%
   GuiControl,, GroupBox2, %GroupBox2TextENG%
   GuiControl,, GroupBox3, %GroupBox3TextENG%
   GuiControl,, CheckQ, %CheckQTextENG%
   GuiControl,, CheckW, %CheckWTextENG%
   GuiControl,, CheckT, %CheckTTextENG%
   GuiControl,, CheckTray, %CheckTrayTextENG%
   GuiControl,, BTNSave, %BTNSaveTextENG%
   GuiControl,, BTNExit, %BTNExitTextENG%
   If ( BTNSubmit = BTNSubmitTextCHS )
      GuiControl,, BTNSubmit, %BTNSubmitTextENG%
   If ( BTNSubmit = BTNSubmitText2CHS )
      GuiControl,, BTNSubmit, %BTNSubmitText2ENG%
   If ( BTNSubmit = BTNSubmitText2ENG )
      GuiControl,, BTNSubmit, %BTNSubmitText2ENG%
}
Else{
   GuiControl,, GroupBox1, %GroupBox1TextCHS%
   GuiControl,, GroupBox2, %GroupBox2TextCHS%
   GuiControl,, GroupBox3, %GroupBox3TextCHS%
   GuiControl,, CheckQ, %CheckQTextCHS%
   GuiControl,, CheckW, %CheckWTextCHS%
   GuiControl,, CheckT, %CheckTTextCHS%
   GuiControl,, CheckTray, %CheckTrayTextCHS%
   GuiControl,, BTNSubmit, %BTNSubmitTextCHS%
   GuiControl,, BTNSave, %BTNSaveTextCHS%
   GuiControl,, BTNExit, %BTNExitTextCHS%
   If ( BTNSubmit = BTNSubmitText2CHS )
      GuiControl,, BTNSubmit, %BTNSubmitText2CHS%
   If ( BTNSubmit = BTNSubmitTextENG )
      GuiControl,, BTNSubmit, %BTNSubmitTextCHS%
   If ( BTNSubmit = BTNSubmitText2ENG )
      GuiControl,, BTNSubmit, %BTNSubmitText2CHS%
}
Return


;////////////////////////////////the button has 2 labels, "start" & "stop", start hotkey and stop hotkey
BTNSUBMIT:
GuiControlGet, BTNSubmit
If ( BTNSubmit = BTNSubmitTextCHS ) || ( BTNSubmit = BTNSubmitTextENG ) {
   If ( BTNSubmit = BTNSubmitTextCHS )
      GuiControl,, BTNSubmit, %BTNSubmitText2CHS%
   Else
      GuiControl,, BTNSubmit, %BTNSubmitText2ENG%
   GuiControl, Enable, BTNSave
   GuiControl, Disabled, KeyNum7
   GuiControl, Disabled, KeyNum4
   GuiControl, Disabled, KeyNum1
   GuiControl, Disabled, KeyNum8
   GuiControl, Disabled, KeyNum5
   GuiControl, Disabled, KeyNum2
   GuiControl, Disabled, CheckQ
   GuiControl, Disabled, CheckW
   GuiControl, Disabled, CheckT
   GuiControl, Disabled, CheckTray
   Gui, Submit, NoHide
   Suspend, Off
   If KeyNum7
      Hotkey, %KeyNum7%, SENDNUM7
   If KeyNum4
      Hotkey, %KeyNum4%, SENDNUM4
   If KeyNum1
      Hotkey, %KeyNum1%, SENDNUM1
   If KeyNum8
      Hotkey, %KeyNum8%, SENDNUM8
   If KeyNum5
      Hotkey, %KeyNum5%, SENDNUM5
   If KeyNum2
      Hotkey, %KeyNum2%, SENDNUM2
   If ( CheckQ = 1 )
      Hotkey, !q, SENDQ
   If ( CheckW = 1 )
      Hotkey, LWin, SENDW
   If ( CheckT = 1 )
      Hotkey, !Tab, SENDT
   If ( CheckTray = 1 ) {
      OnMessage(0x112,"WM_SYSCOMMAND")
      WM_SYSCOMMAND(wParam)                     ;////////minimize to tray
      {
         if (A_Gui && wParam = 0xF020)     ;/////// SC_MINIMIZE
         {
            Gui, Hide
            Menu, Tray, Icon          ;/////GUI hide, trayicon show
            Gosub, MENUCREATE         ;/////Create tray menu
            Return 0
         }
      }
   }
}
Else{
   If ( BTNSubmit = BTNSubmitText2CHS )
      GuiControl,, BTNSubmit, %BTNSubmitTextCHS%
   Else
      GuiControl,, BTNSubmit, %BTNSubmitTextENG%
   GuiControl, Disabled, BTNSave
   GuiControl, Enable, KeyNum7
   GuiControl, Enable, KeyNum4
   GuiControl, Enable, KeyNum1
   GuiControl, Enable, KeyNum8
   GuiControl, Enable, KeyNum5
   GuiControl, Enable, KeyNum2
   GuiControl, Enable, CheckQ
   GuiControl, Enable, CheckW
   GuiControl, Enable, CheckT
   GuiControl, Enable, CheckTray
   Suspend, On
   OnMessage(0x112,"")
}
Return


;///////////////////////////////////////Create tray menu
MENUCREATE:
GuiControlGet, BTNExit
If ( BTNExit = BTNExitTextCHS ) {
   LangMenuShow = %MenuShowTextCHS%
   LangMenuStart = %BTNSubmitTextCHS%
   LangMenuStop = %BTNSubmitText2CHS%
   LangMenuExit = %BTNExitTextCHS%
}
Else{
   LangMenuShow = %MenuShowTextENG%
   LangMenuStart = %BTNSubmitTextENG%
   LangMenuStop = %BTNSubmitText2ENG%
   LangMenuExit = %BTNExitTextENG%
}
Menu, Tray, NoStandard
Menu, Tray, Add, %LangMenuShow%, MENUSHOW
Menu, Tray, Default, %LangMenuShow%
Menu, Tray, Add
Menu, Tray, Add, %LangMenuStart%, MENUSTART
Menu, Tray, Disable, %LangMenuStart%,
Menu, Tray, Add, %LangMenuStop%, MENUSTOP
Menu, Tray, Add
Menu, Tray, Add, %LangMenuExit%, GUICLOSE
Menu, Tray, Click, 1
Return


;/////////////////////////////////////////GUI show again, no trayicon, delete menu
MENUSHOW:
Gui, Show
Menu, Tray, DeleteAll
Menu, Tray, NoIcon
Return

MENUSTART:
Suspend, Off
Menu, Tray, Disable, %LangMenuStart%
Menu, Tray, Enable, %LangMenuStop%
If ( LangMenuStart = BTNSubmitTextCHS )
   GuiControl,, BTNSubmit, %BTNSubmitText2CHS%
Else
   GuiControl,, BTNSubmit, %BTNSubmitText2ENG%
GuiControl, Enable, BTNSave
GuiControl, Disabled, KeyNum7
GuiControl, Disabled, KeyNum4
GuiControl, Disabled, KeyNum1
GuiControl, Disabled, KeyNum8
GuiControl, Disabled, KeyNum5
GuiControl, Disabled, KeyNum2
GuiControl, Disabled, CheckQ
GuiControl, Disabled, CheckW
GuiControl, Disabled, CheckT
GuiControl, Disabled, CheckTray
OnMessage(0x112,"WM_SYSCOMMAND")
Return


MENUSTOP:
Suspend, On
Menu, Tray, Enable, %LangMenuStart%
Menu, Tray, Disable, %LangMenuStop%
If ( LangMenuStop = BTNSubmitText2CHS )
   GuiControl,, BTNSubmit, %BTNSubmitTextCHS%
Else
   GuiControl,, BTNSubmit, %BTNSubmitTextENG%
GuiControl, Disabled, BTNSave
GuiControl, Enable, KeyNum7
GuiControl, Enable, KeyNum4
GuiControl, Enable, KeyNum1
GuiControl, Enable, KeyNum8
GuiControl, Enable, KeyNum5
GuiControl, Enable, KeyNum2
GuiControl, Enable, CheckQ
GuiControl, Enable, CheckW
GuiControl, Enable, CheckT
GuiControl, Enable, CheckTray
OnMessage(0x112,"")
Return


;//////////////////////////////Save config to file
SAVECONF:
Gui, Submit, NoHide
IniWrite, %KeyNum7%, %AppName%.cfg, Settings, Num7
IniWrite, %KeyNum4%, %AppName%.cfg, Settings, Num4
IniWrite, %KeyNum1%, %AppName%.cfg, Settings, Num1
IniWrite, %KeyNum8%, %AppName%.cfg, Settings, Num8
IniWrite, %KeyNum5%, %AppName%.cfg, Settings, Num5
IniWrite, %KeyNum2%, %AppName%.cfg, Settings, Num2
IniWrite, %CheckQ%, %AppName%.cfg, Settings, ALT-Q
IniWrite, %CheckW%, %AppName%.cfg, Settings, WIN
IniWrite, %CheckT%, %AppName%.cfg, Settings, ALT-TAB
IniWrite, %CheckTray%, %AppName%.cfg, Settings, Tray
Return


;/////////////////////////////////////////Read config file
READCONF:
IfExist, %AppName%.cfg
{
   IniRead, Num7, %AppName%.cfg, Settings, Num7
   IniRead, Num4, %AppName%.cfg, Settings, Num4
   IniRead, Num1, %AppName%.cfg, Settings, Num1
   IniRead, Num8, %AppName%.cfg, Settings, Num8
   IniRead, Num5, %AppName%.cfg, Settings, Num5
   IniRead, Num2, %AppName%.cfg, Settings, Num2
   IniRead, CHKQ, %AppName%.cfg, Settings, ALT-Q
   IniRead, CHKW, %AppName%.cfg, Settings, WIN
   IniRead, CHKT, %AppName%.cfg, Settings, ALT-TAB
   IniRead, CHKTray, %AppName%.cfg, Settings, Tray
   If ( CHKQ = 0 )
      StatusQ = UnCheck
   If ( CHKW = 0 )
      StatusW = UnCheck
   If ( CHKT = 0 )
      StatusT = UnCheck
   If ( CHKTray = 0 )
      StatusTray = UnCheck
}
Return


;///////////////////////////////////Remap key
SENDNUM7:
SendPlay, {Numpad7}
Return


SENDNUM4:
SendPlay, {Numpad4}
Return


SENDNUM1:
SendPlay, {Numpad1}
Return


SENDNUM8:
SendPlay, {Numpad8}
Return


SENDNUM5:
SendPlay, {Numpad5}
Return


SENDNUM2:
SendPlay, {Numpad2}
Return


SENDQ:
Send, q
Return


SENDW:
Return


SENDT:
Send, {Tab}
Return


GUICLOSE:
ExitApp
Back to top
View user's profile Send private message
TheIrishThug



Joined: 19 Mar 2006
Posts: 381

PostPosted: Tue Mar 18, 2008 7:04 pm    Post subject: Reply with quote

You could put an event on all the hotkey controls that checks if any of them match. From there you can decide if you want to force the user to change the old one first or simply set the old one to blank.
Back to top
View user's profile Send private message Visit poster's website AIM Address
GoAPE



Joined: 15 Mar 2008
Posts: 9

PostPosted: Tue Mar 18, 2008 7:58 pm    Post subject: Reply with quote

TheIrishThug wrote:
You could put an event on all the hotkey controls that checks if any of them match. From there you can decide if you want to force the user to change the old one first or simply set the old one to blank.


omg!!~~ too many work, is there any easy solution?
and how to set it to blank?
Back to top
View user's profile Send private message
GoAPE



Joined: 15 Mar 2008
Posts: 9

PostPosted: Tue Mar 18, 2008 8:09 pm    Post subject: Reply with quote

i think i have known how to set it to blank.

is there any better solution?
Back to top
View user's profile Send private message
TheIrishThug



Joined: 19 Mar 2006
Posts: 381

PostPosted: Tue Mar 18, 2008 8:40 pm    Post subject: Reply with quote

You've already used all the commands you would need to understand in order to write this feature. The only thing making this somewhat difficult is that you didn't simply name the controls Hotkey1-6.
Code:
HotkeyCheck:
Gui, Submit, NoHide
; loops and if statements to check if there is a conflict
GuiControl, , %conflicting_control%,
Back to top
View user's profile Send private message Visit poster's website AIM Address
GoAPE



Joined: 15 Mar 2008
Posts: 9

PostPosted: Tue Mar 18, 2008 9:01 pm    Post subject: Reply with quote

too many,



Code:
Gui, Add, Hotkey, w100 h30 vHotkey1 gSAMECHECK1, 1
Gui, Add, Hotkey, w100 h30 vHotkey2 gSAMECHECK2, 2
Gui, Add, Hotkey, w100 h30 vHotkey3 gSAMECHECK3, 3
Gui, Add, Hotkey, w100 h30 vHotkey4 gSAMECHECK4, 4
Gui, Add, Hotkey, w100 h30 vHotkey5 gSAMECHECK5, 5
Gui, Add, Hotkey, w100 h30 vHotkey6 gSAMECHECK6, 6
Gui, Show, w125 h225, Hotkey Test
Return

GuiClose:
ExitApp

SAMECHECK1:
Gui, Submit, NoHide
If Hotkey1=%Hotkey2%
   GuiControl,, Hotkey2,
If Hotkey1=%Hotkey3%
   GuiControl,, Hotkey3,
If Hotkey1=%Hotkey4%
   GuiControl,, Hotkey4,
If Hotkey1=%Hotkey5%
   GuiControl,, Hotkey5,
If Hotkey1=%Hotkey6%
   GuiControl,, Hotkey6,
Return

SAMECHECK2:
Gui, Submit, NoHide
If Hotkey2=%Hotkey1%
   GuiControl,, Hotkey1,
If Hotkey2=%Hotkey3%
   GuiControl,, Hotkey3,
If Hotkey2=%Hotkey4%
   GuiControl,, Hotkey4,
If Hotkey2=%Hotkey5%
   GuiControl,, Hotkey5,
If Hotkey2=%Hotkey6%
   GuiControl,, Hotkey6,
Return

SAMECHECK3:
Gui, Submit, NoHide
If Hotkey3=%Hotkey2%
   GuiControl,, Hotkey2,
If Hotkey3=%Hotkey1%
   GuiControl,, Hotkey1,
If Hotkey3=%Hotkey4%
   GuiControl,, Hotkey4,
If Hotkey3=%Hotkey5%
   GuiControl,, Hotkey5,
If Hotkey3=%Hotkey6%
   GuiControl,, Hotkey6,
Return

SAMECHECK4:
Gui, Submit, NoHide]
If Hotkey4=%Hotkey2%
   GuiControl,, Hotkey2,
If Hotkey4=%Hotkey3%
   GuiControl,, Hotkey3,
If Hotkey4=%Hotkey1%
   GuiControl,, Hotkey1,
If Hotkey4=%Hotkey5%
   GuiControl,, Hotkey5,
If Hotkey4=%Hotkey6%
   GuiControl,, Hotkey6,
Return

SAMECHECK5:
Gui, Submit, NoHide
If Hotkey5=%Hotkey2%
   GuiControl,, Hotkey2,
If Hotkey5=%Hotkey3%
   GuiControl,, Hotkey3,
If Hotkey5=%Hotkey4%
   GuiControl,, Hotkey4,
If Hotkey5=%Hotkey1%
   GuiControl,, Hotkey1,
If Hotkey5=%Hotkey6%
   GuiControl,, Hotkey6,
Return

SAMECHECK6:
Gui, Submit, NoHide
If Hotkey6=%Hotkey2%
   GuiControl,, Hotkey2,
If Hotkey6=%Hotkey3%
   GuiControl,, Hotkey3,
If Hotkey6=%Hotkey4%
   GuiControl,, Hotkey4,
If Hotkey6=%Hotkey5%
   GuiControl,, Hotkey5,
If Hotkey6=%Hotkey1%
   GuiControl,, Hotkey1,
Return
Back to top
View user's profile Send private message
Kellianjaxon



Joined: 04 Jan 2008
Posts: 39

PostPosted: Wed Mar 19, 2008 1:14 am    Post subject: Reply with quote

You can noticably shorten the code by using a single subroutine with a loop to check for a hotkey duplicate. Proper usage of built-in variables A_index and A_GuiControl is going to get you to your goal.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   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