Recently, I wrote this script to help me remap my windows mouse left button, but some error happened.
Code: Select all
InputBox, UserInput, Testing, `n`r(Choose a new key .), , 360, 200
MsgBox, You entered "%UserInput%"
UserInput::LButton
Kitty
Code: Select all
InputBox, UserInput, Testing, `n`r(Choose a new key .), , 360, 200
MsgBox, You entered "%UserInput%"
UserInput::LButton
Code: Select all
#Persistent
InputBox, UserInput, Testing, `n`r(Choose a new key .), , 360, 200
MsgBox, You entered "%UserInput%"
Hotkey, %UserInput%, RemapKey
RemapKey:
SendEvent {LButton}
return
esc::exitapp
Thank you for the help!noname wrote:As far as i known you can only use a variable with the hotkey command:
see : https://autohotkey.com/docs/commands/Hotkey.htm
Code: Select all
#Persistent InputBox, UserInput, Testing, `n`r(Choose a new key .), , 360, 200 MsgBox, You entered "%UserInput%" Hotkey, %UserInput%, RemapKey RemapKey: SendEvent {LButton} return esc::exitapp
Code: Select all
#Persistent
InputBox, UserInput, Testing, `n`r(Choose a new key .), , 360, 200
MsgBox, You entered "%UserInput%"
Hotkey, %UserInput%, RemapKey
RemapKey(){
SendEvent {LButton}
}
return
esc::exitapp
I used Remapkey as a label , but as a function it looks better (but you need a recent version of ahk)If not a valid label name, this parameter can be the name of a function
Code: Select all
#SingleInstance force
#NoEnv
#Include AppFactory.ahk
; Initialize AppFactory
factory := new AppFactory()
; Add a custom Hotkey GuiControl called HK1, and set it to fire the InputEvent() function when it changes state
; The "w200" parameter is for size / position of the control, and is in the same format as when adding a normal AHK GuiControl
; ie this is basically saying the same thing as
; Gui, Add, Hotkey, w200
factory.AddInputButton("HK1", "w200", Func("InputEvent"))
Gui, Show
return
; This function gets called when the hotkey is pressed or released
; State holds 1 if the button was pressed, or 0 if it was released
InputEvent(state){
Tooltip % "Button State: " state
; Send output in response to the input
if (state){
Send {Lbutton down}
} else {
Send {Lbutton up}
}
}
^Esc::
GuiClose:
ExitApp
Code: Select all
#SingleInstance force
#NoEnv
#Include AppFactory.ahk
factory := new AppFactory()
factory.AddInputButton("HK1", "w200", Func("InputEvent"))
; Add a custom, peristent EditBox to hold the name of the key to send in response to the hotkey
; Set the default value to "LButton"
factory.AddControl("KeyToSend", "Edit", "xm w200", "LButton", 0)
Gui, Show, x0 y0
return
InputEvent(state){
global factory
; Get the name of the key to send from the KeyToSend EditBox
keyToSend := factory.GuiControls.KeyToSend.Get()
if (state){
Send { %keyToSend% down}
} else {
Send { %keyToSend% up}
}
}
^Esc::
GuiClose:
ExitApp