Get a script working without disabling Shift

Get help with using AutoHotkey and its commands and hotkeys
Krats
Posts: 1
Joined: 16 Oct 2018, 16:36

Get a script working without disabling Shift

16 Oct 2018, 17:38

For context, I am trying to override the camera controls in Autodesk Maya. By default, Alt + LMB = Orbit and Alt + MMB = Pan. Not only that, but also LMB and MMB can be swapped between as many times as you like without having to release Alt. I would like to do the same, except I want MMB = Orbit and Shift + MMB = Pan, in which I can toggle Shift as many times as I like.

I've got the following so far:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#MenuMaskKey vk07
#ifWinActive ahk_exe maya.exe

LShift:: return

Pan()
{
	SendInput {MButton Down}
		Loop 
	{
		KeyWait, LShift, T0.01 ;Pan to Orbit
		If not ErrorLevel 
		{
		SendInput {MButton Up}
		if (Orbit())
		return true
		}

		KeyWait, MButton, T0.01 ;Pan to Exit
		If not ErrorLevel
		{
		SendInput {MButton Up}
		return true
		}
	}
}

Orbit()
{
	SendInput {LButton Down}

			Loop 
	{
		KeyWait, LShift, D T0.01 ;Orbit to Pan
		If not ErrorLevel 
		{
		SendInput {LButton Up}
		if (Pan())
		return true
		}

		KeyWait, MButton, T0.01 ;Orbit to Exit
		If not ErrorLevel
		{
		SendInput {LButton Up}
		return true
		}
	}
}

MButton::

if (GetKeyState LShift, P) 
{
	SendInput {LAlt Down}
	if Pan()
	{
	SendInput {LAlt Up}
	}
}

else 
{
	SendInput {LAlt Down}
	if Orbit() 
	{
	SendInput {LAlt Up}
	}
}
I realise it's maybe a bit silly, but it does do exactly what I want it to do. The only problem is LShift is permanently disabled. I tried putting in Hotkey LShift, On and Hotkey LShift, Off or even a foo::Hotkey LShift, Toggle to toggle it manually, but it always seems to mess things up. Then again I might not be using Hotkey correctly. Does anyone have any ideas?
rommmcek
Posts: 375
Joined: 15 Aug 2014, 15:18

Re: Get a script working without disabling Shift

17 Oct 2018, 06:34

Above solution may trigger context menu by pressing LShift down. To block it try:

Code: Select all

#If mouseOverMaya()
	~LShift::return
#If

 mouseOverMaya() {
	MouseGetPos,,, WinId
	WinGetTitle, WinT, ahk_id %WinId%
	if (WinT="Autodesk Maya") ; Insert correct Win Title
		return true
 }

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], kadhri, paik1002 and 134 guests