Page 1 of 1

Hotkey Function

Posted: 16 Oct 2019, 12:16
by Zitrone
Hello everyone,

i have a little problem with my AHK script. My "Hotkey" command is not working right, maybe you can tell me what im doing wrong.

Code: Select all

#IfWinActive, GTA:SA:MP
#Include SAMP.ahk
#Persistent
#UseHook
#SingleInstance Force
#NoEnv

;Keybinder Startup Msg.
SetTimer, Startup, On

;INI READ
IniRead,taste_1,settings.ini,Keybinds, taste_1
IniRead,taste_2,settings.ini,Keybinds, taste_2
IniRead,taste_3,settings.ini,Keybinds, taste_3
IniRead,taste_4,settings.ini,Keybinds, taste_4
IniRead,taste_5,settings.ini,Keybinds, taste_5
IniRead,taste_6,settings.ini,Keybinds, taste_6
IniRead,taste_7,settings.ini,Keybinds, taste_7
IniRead,taste_8,settings.ini,Keybinds, taste_8
IniRead,taste_9,settings.ini,Keybinds, taste_9
IniRead,taste_10,settings.ini,Keybinds, taste_10




;Gui
Gui, Show, w400 h320, Terroristen Keybinder v 1.0 
Gui, Add, Tab2, x2 y-1 w400 h350 , Terror Keybinds|Eigene Keybinds|Einstellungen

; Terror Keybinds // HOTKEY
Gui, Add, Hotkey, x10 y25 vtaste_1, %taste_1%
Gui, Add, Hotkey, x10 y50 vtaste_2, %taste_2%
Gui, Add, Hotkey, x10 y75 vtaste_3, %taste_3%
Gui, Add, Hotkey, x10 y100 vtaste_4, %taste_4%
Gui, Add, Hotkey, x10 y125 vtaste_5, %taste_5%
Gui, Add, Hotkey, x10 y150 vtaste_6, %taste_6%
Gui, Add, Hotkey, x10 y175 vtaste_7, %taste_7%
Gui, Add, Hotkey, x10 y200 vtaste_8, %taste_8%
Gui, Add, Hotkey, x10 y225 vtaste_9, %taste_9%
Gui, Add, Hotkey, x10 y250 vtaste_10, %taste_10%

;Terror Keybind // Text
Gui, Add, Text, x150 y25, TEST
Gui, Add, Text, x150 y50, TEST
Gui, Add, Text, x150 y75, TEST
Gui, Add, Text, x150 y100, TEST
Gui, Add, Text, x150 y125, TEST
Gui, Add, Text, x150 y150, TEST
Gui, Add, Text, x150 y175, TEST
Gui, Add, Text, x150 y200, TEST
Gui, Add, Text, x150 y225, TEST
Gui, Add, Text, x150 y250, TEST

Gui, Add, Button, x0 y290 w400 h25 gSpeichern, Speichern
return







GuiClose:
ExitApp

;Hotkey Definition

Hotkey,%taste_1%,Waschen, UserErrorlevel
return

;Hotkeys

Waschen:
SendInput, t/s WASCHEN! {enter}
return

Speichern:
Gui,Submit,Nohide
IniWrite, %taste_1%,settings.ini,Keybinds, taste_1
IniWrite, %taste_2%,settings.ini,Keybinds, taste_2
IniWrite, %taste_3%,settings.ini,Keybinds, taste_3
IniWrite, %taste_4%,settings.ini,Keybinds, taste_4
IniWrite, %taste_5%,settings.ini,Keybinds, taste_5
IniWrite, %taste_6%,settings.ini,Keybinds, taste_6
IniWrite, %taste_7%,settings.ini,Keybinds, taste_7
IniWrite, %taste_8%,settings.ini,Keybinds, taste_8
IniWrite, %taste_9%,settings.ini,Keybinds, taste_9
IniWrite, %taste_10%,settings.ini,Keybinds, taste_10
MsgBox, 0,, %taste_1%.
return


;Keybinder Init
t::
Suspend On
SendInput t
Hotkey, Enter, On
Hotkey, Escape, On
Hotkey, t, Off
return
 
NumpadEnter::
Enter::
Suspend Permit
Suspend Off
SendInput {Enter}
Hotkey, t, On
Hotkey, Enter, Off
Hotkey, Escape, Off
return
 
Escape::
Suspend Permit
Suspend Off
SendInput {Escape}
Hotkey, t, On
Hotkey, Enter, Off
Hotkey, Escape, Off
return


Startup:
GetChatLine(0, Startup, timestamp=0, color=0)
If (InStr(Startup, "Connected to Life"))
{
addChatMessage("{FF0033}[Terroristen Keybinder v.1.0 by Artemis loaded]")
}
return



Numpad0::
SendInput, t/s NIX LOS HIER {ENTER}
return



Thank you for your help!

I cant get this command "Hotkey,%taste_1%,Waschen, UserErrorlevel" working.

Re: Hotkey Function

Posted: 16 Oct 2019, 18:06
by gregster
Welcome to the forum!

Zitrone wrote:
16 Oct 2019, 12:16
I cant get this command "Hotkey,%taste_1%,Waschen, UserErrorlevel" working.
If you want to create/define/modify a hotkey during script execution via the Hotkey command (in contrast to the more common label-::-method), you have to make sure that the command gets executed at some point, before you can use that hotkey.

At the moment, the line Hotkey,%taste_1%,Waschen, UserErrorlevel is absolutely unreachable in your code and gets never executed. The last command above it, is ExitApp - how should the code flow of execution get to the Hotkey-line after that?:

Code: Select all

; [...]
GuiClose:
ExitApp		; at this point the script exits

;Hotkey Definition

Hotkey,%taste_1%,Waschen, UserErrorlevel	; this is unreachable
return
; [...]
I imagine that you want this Hotkey-line executed in the Speichern:-subroutine instead, when you also save the hotkeys to an ini-file and after actually submitting the variables from the GUI.