Pressing 1 key changes a bunch of keybinds at once, pressing another key rewrites said keys to something else.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Delkin52
Posts: 3
Joined: 13 Jan 2022, 11:22

Pressing 1 key changes a bunch of keybinds at once, pressing another key rewrites said keys to something else.

Post by Delkin52 » 02 Oct 2022, 00:33

Hey guys,

I'm not sure how to approach a script like this. I've googled this for a bit and haven't been successful finding much. Here's what I'm trying to do. I'm using a 3D program and I'd like when I enter a specific tool (like when I press B for brush[painting]) all of my keys change to suit a painting environment. But if I click another key, such as "S" it switches to all of my sculpting binds, replacing my painting key binds.

Thanks so much for your time and help! :D

User avatar
boiler
Posts: 16912
Joined: 21 Dec 2014, 02:44

Re: Pressing 1 key changes a bunch of keybinds at once, pressing another key rewrites said keys to something else.

Post by boiler » 02 Oct 2022, 01:49

Pretty straightforward:

Code: Select all

Mode := "b" ; set initial default mode
return

b::
s::
	Mode := A_ThisHotkey
	SoundBeep
return

#If Mode = "b"
; all the definitions of your hotkeys for brush mode go here
x::MsgBox, You pressed "X" while in brush mode

#If Mode = "s"
; all the definitions of your hotkeys for sculpting mode go here
x::MsgBox, You pressed "X" while in sculpting mode


Don’t change anything in the above script other than to add the hotkeys for each mode where the comment lines say to add them. You can remove the example x hotkeys, of course. They are there to demonstrate that the same key has a different action depending on what mode you’re in.

Tensai
Posts: 29
Joined: 12 Dec 2019, 14:15

Re: Pressing 1 key changes a bunch of keybinds at once, pressing another key rewrites said keys to something else.

Post by Tensai » 02 Oct 2022, 02:08

Here's a sample template of how to do this in v2. Same concept as @boiler . Substitute "ahk_exe notepad.exe" with your 3D program.

Code: Select all

Escape::ExitApp ; optional, use Escape for this script to exit.
global brushMode:=0
global sculptMode:=0

#HotIf WinActive("ahk_exe notepad.exe")
b::{	; brushMode
	global
	sculptMode:=0
	brushMode:=1
	Tip("Brush Mode")
}
s::{	; sculptMode
	global
	brushMode:=0
	sculptMode:=1
	Tip("Sculpt Mode")
}
d::{	; default
	global
	brushMode:=0
	sculptMode:=0
	Tip("Default Mode")
}

#HotIf WinActive("ahk_exe notepad.exe") and brushMode
a::{
	Tip("a pressed in brushMode")
}

#HotIf Winactive("ahk_exe notepad.exe") and sculptMode=1
a::{
	Tip("a pressed in sculptMode")
}

#HotIf	; turn off context sensitivity

Tip(Text:=""){	; Function to Display Tooltip Text for 1 Second
	ToolTip(Text)
	SetTimer(ToolTip,-1000)
}

Delkin52
Posts: 3
Joined: 13 Jan 2022, 11:22

Re: Pressing 1 key changes a bunch of keybinds at once, pressing another key rewrites said keys to something else.

Post by Delkin52 » 03 Oct 2022, 01:29

Amazing! Thanks for the help guys, I'll give this a shot! :D

Post Reply

Return to “Ask for Help (v1)”