1 (изменено: aktor311, 2017-08-29 18:54:26)

Тема: AHK: Обозначение клавиши скрипта через Hotkey

С подобным вопросом уже обращался. Вроде понял саму систему назначения hotkey на клавиши скрипта. Но все же возник вопрос:

PathIni = IniFile.ini
IniRead, MyGuiHotkey, % PathIni, Section, MyGuiHotkey, % A_Space
Hotkey, % PrSetSuspend := MyGuiHotkey, !1, UseErrorLevel
Gui, Font, S16 CGray, Verdana
FileInstall, C:\Users\User\Desktop\1470403006_geroi.png, %A_temp%\1470403006_geroi.png
Gui, Add, Picture, x-38 y-10 w520 h560 , %A_temp%\1470403006_geroi.png
Gui, Add, Text, x22 y10 w210 h30 BackgroundTrans, Введите клавишу.
Gui, Add, Text, x22 y60 w100 h30 BackgroundTrans, Броня
Gui, Add, Text, x282 y60 w100 h30 BackgroundTrans, Баты
Gui, Add, Hotkey, x52 y110 w100 h30 gSetSuspend vMyGuiHotkey, %MyGuiHotkey%
Gui, Add, Hotkey, x312 y110 w100 h30 , 
Gui, Add, Text, x2 y110 w30 h30 BackgroundTrans, 1.
Gui, Add, Text, x2 y160 w30 h30 BackgroundTrans, 2
Gui, Add, Hotkey, x52 y160 w100 h30 , 
Gui, Add, Hotkey, x312 y160 w100 h30 , 
Gui, Add, Text, x2 y210 w30 h30 BackgroundTrans, 3.
Gui, Add, Text, x2 y260 w30 h30 BackgroundTrans, 4.
Gui, Add, Hotkey, x312 y210 w100 h30 , 
Gui, Add, Hotkey, x312 y260 w100 h30 , 
Gui, Add, Button, x422 y110 w40 h30 , Ок
Gui, Add, Button, x422 y160 w40 h30 , Ок
Gui, Add, Button, x422 y210 w40 h30 , Ок
Gui, Add, Button, x422 y260 w40 h30 , Ок
Gui, Add, Button, x162 y110 w40 h30 , Ок
Gui, Add, Button, x162 y160 w40 h30 , Ок
; Generated using SmartGUI Creator for SciTE
Gui, Show, w478 h438, Untitled GUI
return
GuiClose:
ExitApp
SetSuspend:
Hotkey, % PrSetSuspend, Off, UseErrorLevel
GuiControlGet, Hotkey, %A_Gui%:, %A_GuiControl% 
Hotkey := FormatHotkey(Hotkey)  
	Hotkey, % PrSetSuspend := Hotkey, 
	IniWrite, % Hotkey, % PathIni, Section, % A_GuiControl
	Return

return




FormatHotkey(Hotkey) {
	RegExMatch(Hotkey, "S)^([\^\+!]*)(.*?)$", K)
	If (StrLen(K2) = 1)
		Return K1 . Format("sc{:X}", GetKeySC(K2))
	Return Hotkey
} 

!1::
{
	Send, {sc12}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	Send, {sc12}
}
return
!2::
{
	Send, {sc12}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	Send, {sc12}
}
return

Я хочу обозначить "!1" что бы она менялась при смене этого hotkey:

Gui, Add, Hotkey, x52 y110 w100 h30 gSetSuspend vMyGuiHotkey, %MyGuiHotkey%

Прошу помочь и если возможно объянить сам принцып.
Вот еще код самого скрипта:

!1::
{
	Send, {sc12}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	Send, {sc12}
}
return
!2::
{
	Send, {sc12}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	Send, {sc12}
}
return

2

Re: AHK: Обозначение клавиши скрипта через Hotkey

Hotkey, %MyGuiHotkey%, MyKey1, On, UseErrorLevel
MyKey1:
msgbox, работает
return
Когда вы говорите что не можете сделать, вам всего-лишь не хватает фантазии придумать какой-нибудь костыль.

3

Re: AHK: Обозначение клавиши скрипта через Hotkey

belyankin12
Можно поподробней?

4 (изменено: aktor311, 2017-08-30 10:45:29)

Re: AHK: Обозначение клавиши скрипта через Hotkey

Пишет что ошибка в этой строке:

Gui, Add, Hotkey, x52 y110 w100 h30 gSetSuspend vMyGuiHotkey, %MyGuiHotkey%

Error: Target label does not exist
Вот полный нынешний код:

PathIni = IniFile.ini
IniRead, MyGuiHotkey, % PathIni, Section, MyGuiHotkey, % A_Space
Hotkey, %MyGuiHotkey%, MyKey1, On, UseErrorLevel
Gui, Font, S16 CGray, Verdana
FileInstall, C:\Users\User\Desktop\1470403006_geroi.png, %A_temp%\1470403006_geroi.png
Gui, Add, Picture, x-38 y-10 w520 h560 , %A_temp%\1470403006_geroi.png
Gui, Add, Text, x22 y10 w210 h30 BackgroundTrans, Введите клавишу.
Gui, Add, Text, x22 y60 w100 h30 BackgroundTrans, Броня
Gui, Add, Text, x282 y60 w100 h30 BackgroundTrans, Баты
Gui, Add, Hotkey, x52 y110 w100 h30 gSetSuspend vMyGuiHotkey, %MyGuiHotkey%
Gui, Add, Hotkey, x312 y110 w100 h30 , 
Gui, Add, Text, x2 y110 w30 h30 BackgroundTrans, 1.
Gui, Add, Text, x2 y160 w30 h30 BackgroundTrans, 2
Gui, Add, Hotkey, x52 y160 w100 h30 , 
Gui, Add, Hotkey, x312 y160 w100 h30 , 
Gui, Add, Text, x2 y210 w30 h30 BackgroundTrans, 3.
Gui, Add, Text, x2 y260 w30 h30 BackgroundTrans, 4.
Gui, Add, Hotkey, x312 y210 w100 h30 , 
Gui, Add, Hotkey, x312 y260 w100 h30 , 
Gui, Add, Button, x422 y110 w40 h30 , Ок
Gui, Add, Button, x422 y160 w40 h30 , Ок
Gui, Add, Button, x422 y210 w40 h30 , Ок
Gui, Add, Button, x422 y260 w40 h30 , Ок
Gui, Add, Button, x162 y110 w40 h30 , Ок
Gui, Add, Button, x162 y160 w40 h30 , Ок
; Generated using SmartGUI Creator for SciTE
Gui, Show, w478 h438, Untitled GUI
return
GuiClose:
ExitApp



MyKey1:
msgbox, работает
return




FormatHotkey(Hotkey) {
	RegExMatch(Hotkey, "S)^([\^\+!]*)(.*?)$", K)
	If (StrLen(K2) = 1)
		Return K1 . Format("sc{:X}", GetKeySC(K2))
	Return Hotkey
} 

!1::
{
	Send, {sc12}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	Send, {sc12}
}
return
!2::
{
	Send, {sc12}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	Send, {sc12}
}
return

Ошибку исправил, но !1 не меняется.

5

Re: AHK: Обозначение клавиши скрипта через Hotkey

Непонятно чего вы хотите от меня. Чтобы вы вместо !1 могли назначить любую клавишу в GUI? Тогда вам нужна ещё одна кнопка для сохранения в ini файле.

Когда вы говорите что не можете сделать, вам всего-лишь не хватает фантазии придумать какой-нибудь костыль.

6

Re: AHK: Обозначение клавиши скрипта через Hotkey

belyankin12
Именно этого я и хочу. Точнее того что бы менять этот !1 через Hotkey который я указал.
Я был бы очень благодарен если бы вы мне с этим помогли. Иначе я бы сюда не писал.

7 (изменено: belyankin12, 2017-08-30 13:18:08)

Re: AHK: Обозначение клавиши скрипта через Hotkey

Рисуйте кнопку ещё одну, которая будет за сохранение отвечать. В моем примере эта кнопка называется Save.

; Это до отображения окна gui
global ini := путь к ини

ifExist, %ini%
    goto true
else
    goto false

false:
IniWrite, Key, %ini%, Hotkeys, Key1
goto true

true:
IniRead, MyGuiHotkey, %ini%, Hotkeys, Key1

; тут гюи

Gui, Submit, NoHide
Hotkey, %MyGuiHotkey%, MyKey1, On, UseErrorLevel
return

Save:
Gui, submit, NoHide
IniWrite, %MyGuiHotkey%, %ini%, Hotkeys, Key1
reload
return

MyKey1:
msgbox, работает
return
Когда вы говорите что не можете сделать, вам всего-лишь не хватает фантазии придумать какой-нибудь костыль.

8 (изменено: aktor311, 2017-08-30 16:11:07)

Re: AHK: Обозначение клавиши скрипта через Hotkey

Если я нигде не ошибся, а я это сделал, то конечный код должен быть таким?

PathIni = IniFile.ini
IniRead, MyGuiHotkey, % PathIni, Section, MyGuiHotkey, % A_Space
Hotkey, %MyGuiHotkey%, MyKey1, On, UseErrorLevel
global ini :=IniFile.ini
ifExist, %ini%
    goto true
else
    goto false

false:
IniWrite, Key, %ini%, Hotkeys, Key1
goto true
true:
IniRead, MyGuiHotkey, %ini%, Hotkeys, Key1
Gui, Font, S16 CGray, Verdana
FileInstall, C:\Users\User\Desktop\1470403006_geroi.png, %A_temp%\1470403006_geroi.png
Gui, Add, Picture, x-38 y-10 w520 h560 , %A_temp%\1470403006_geroi.png
Gui, Add, Text, x22 y10 w210 h30 BackgroundTrans, Введите клавишу.
Gui, Add, Text, x22 y60 w100 h30 BackgroundTrans, Броня
Gui, Add, Text, x282 y60 w100 h30 BackgroundTrans, Баты
Gui, Add, Hotkey, x52 y110 w100 h30 vMyGuiHotkey vSave, %MyGuiHotkey%
Gui, Add, Hotkey, x312 y110 w100 h30 , 
Gui, Add, Text, x2 y110 w30 h30 BackgroundTrans, 1.
Gui, Add, Text, x2 y160 w30 h30 BackgroundTrans, 2
Gui, Add, Hotkey, x52 y160 w100 h30 , 
Gui, Add, Hotkey, x312 y160 w100 h30 , 
Gui, Add, Text, x2 y210 w30 h30 BackgroundTrans, 3.
Gui, Add, Text, x2 y260 w30 h30 BackgroundTrans, 4.
Gui, Add, Hotkey, x312 y210 w100 h30 , 
Gui, Add, Hotkey, x312 y260 w100 h30 , 
Gui, Add, Button, x422 y110 w40 h30 , Ок
Gui, Add, Button, x422 y160 w40 h30 , Ок
Gui, Add, Button, x422 y210 w40 h30 , Ок
Gui, Add, Button, x422 y260 w40 h30 , Ок
Gui, Add, Button, x162 y110 w40 h30 , Ок
Gui, Add, Button, x162 y160 w40 h30 , Ок
; Generated using SmartGUI Creator for SciTE
Gui, Show, w478 h438, Untitled GUI
return
GuiClose:
ExitApp
Gui, Submit, NoHide
Hotkey, %MyGuiHotkey%, MyKey1, On, UseErrorLevel
return
Save:
Gui, submit, NoHide
IniWrite, %MyGuiHotkey%, %ini%, Hotkeys, Key1
reload
return
MyKey1:
msgbox, работает
return
!1::
{
	Send, {sc12}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 418, 510
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 418, 535
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 418, 570
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 418, 600
	Send, {Lbutton}
	Send, {sc12}
}
return
!2::
{
	Send, {sc12}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 497, 312
	Send, {Lbutton}
	MouseMove, 468, 510
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 497, 347
	Send, {Lbutton}
	MouseMove, 468, 535
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 497, 382
	Send, {Lbutton}
	MouseMove, 468, 570
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	MouseMove, 497, 420
	Send, {Lbutton}
	MouseMove, 468, 600
	Send, {Lbutton}
	Send, {sc12}
}
return

Просто не меняет !1.
Или я тут с кнопкой накосячил, или с порядком не могу понять.

9 (изменено: belyankin12, 2017-08-30 17:22:31)

Re: AHK: Обозначение клавиши скрипта через Hotkey

Как он по вашему поменяет !1 если он черным по белому записан в файле? При нажатии на клавишу заданную в hotkey идёт направление на метку MyKey1, а не на !1. Перед GuiClose уберите return и перенесите эту метку вместе с его действиями вниз, например после save, а !1:: на MyKey1: поменяйте. И с кнопкой накосячили, а точнее со всеми кнопками. Ни одна из ваших кнопок не вызовет ни одного действия.

Когда вы говорите что не можете сделать, вам всего-лишь не хватает фантазии придумать какой-нибудь костыль.

10 (изменено: shahlik002, 2017-08-30 18:32:29)

Re: AHK: Обозначение клавиши скрипта через Hotkey

Вот так вы хотели?

IfExist,MyHotkey.ini
	IniRead,H1,MyHotkey.ini,Hotkeys,Hotkey

HotkeyState=Off
gui,add,hotkey,vH1 ,%H1%
gui,add,button,gB1 vB1 ,Включить
gui,show
return

B1:
if HotkeyState=Off
{
	gui,submit,nohide
		if H1=
			return
	hotkey,%H1%,HotkeyLabel,on
	HotkeyState=On
	GuiControl,text,B1,Выключить
	GuiControl,Disable,H1
}
else if HotkeyState=On
{
	hotkey,%H1%,HotkeyLabel,off
	HotkeyState=Off
	GuiControl,text,B1,Включить
	GuiControl,Enable,H1
}
return

HotkeyLabel:
MsgBox, Сработал Hotkey
return

GuiEscape:
GuiClose:
gui,submit,nohide
IniWrite,%H1%,MyHotkey.ini,Hotkeys,Hotkey
ExitApp

11

Re: AHK: Обозначение клавиши скрипта через Hotkey

aktor311
Принцип состоит в том что бы не начинать строку с хоткея который не меняется (1::).
А задать вместо этого метку (1:) , и назначить на угодную вам кнопку переход к этой метке (hotkey,!1,1).

Если поступить таким образом - выходит что нужную вам кнопку можно задать в переменную (переменная=!1).
И при желании назначать на нее переход к нужной вам метке (hotkey,%переменная%,1)

Также есть функции которые пишутся после метки (hotkey,%переменная%,1,On или hotkey,%переменная%,1,Off (вкл/выкл)).
С помощью них , при желании можно включать , отключать , и производить все прочие махинации .

А вот главный принцип участников этого форума - читать статьи которые пишут специально для них.
Вот статья нашего форума на русском: http://www.script-coding.com/AutoHotkey/Hotkey.html
Вот на официальном сайте: https://autohotkey.com/docs/commands/Hotkey.htm

12

Re: AHK: Обозначение клавиши скрипта через Hotkey

aktor311 пишет:

Вот еще код самого скрипта:

Лучше вот так:

Send, {sc12}{click, 468, 510}{click, 497, 312}{click, 468, 510}{click, 468, 535}{click, 497, 347}{click, 468, 535}{click, 468, 570}{click, 497, 382}{click, 468, 570}{click, 468, 600}{click, 497, 420}{click, 468, 600}{sc12}

13 (изменено: aktor311, 2017-08-30 19:45:28)

Re: AHK: Обозначение клавиши скрипта через Hotkey

Понял сейчас попробую