Jump to content


Photo

Program/Process specific hotkeys


  • Please log in to reply
6 replies to this topic

#1 Demian

Demian
  • Members
  • 20 posts

Posted 21 October 2012 - 05:02 PM

I'm trying to create process(/program) specific hotkeys. I've already managed to get the process verifying to work with some help from the IRC channel. Now I need some help with the hotkeys themselves.

Simply put when the specified window is running I want specific hotkeys to become available. Pressing these hotkeys when the specified window is not active does nothing.

I tried using the Hotkey command but I get a "Target label does not exist" error.

#Persistent ;Keep script running until stopped
WinProc= ;Window process name

;--------------------------------
; Hooks and stuff, I have no idea what any of this does
;--------------------------------
Gui +LastFound
hWnd:=WinExist()

DllCall("RegisterShellHookWindow", UInt,hWnd)
MsgNum:=DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(MsgNum, "ShellMessage")

return

;--------------------------------
; Wait for a window to be activated
;--------------------------------
ShellMessage(wParam,lParam)
{
	if (wParam != 4) ;Check if the window is activated
		return

	WinGet, WinProc, ProcessName, A
	
	;Check for Blender process
	if (WinProc="blender.exe") 
	{
		Step1Key=F4

		Hotkey, %Step1Key%, gStep1Sub
		
		Step1Sub:
			MsgBox, Running Step1 subroutine
	}
}


#2 HotKeyIt

HotKeyIt
  • Fellows
  • 6132 posts

Posted 21 October 2012 - 05:42 PM

Are you using AHK_L?

Process Name/Path (ahk_exe) v1.1.01+: While ahk_pid is limited to one specific process, ahk_exe considers all processes with name or full path matching a given string. If the RegEx title matching mode is active, ahk_exe accepts a regular expression. Otherwise, ahk_exe accepts a case-insensitive name or full path; for example, ahk_exe notepad.exe covers ahk_exe C:\Windows\Notepad.exe, ahk_exe C:\Windows\System32\Notepad.exe and other variations.

#IfWinActive ahk_exe blender.exe
   F4::MsgBox
#IfWinActive


#3 Demian

Demian
  • Members
  • 20 posts

Posted 22 October 2012 - 09:28 AM

No I'm not and it seems that code only works on the L version.
Edit: Huh, seems to work fine on the regular version. I guess I'll use this code then!

#4 HotKeyIt

HotKeyIt
  • Fellows
  • 6132 posts

Posted 22 October 2012 - 12:42 PM

This works in AHK_L only, probably you have it, what do you get here:
MsgBox % A_AhkVersion


#5 TLM

TLM
  • Members
  • 3591 posts

Posted 22 October 2012 - 01:12 PM

Unless I'm missing something here,
trying to use a shellmessage for this is extreme and unnecessary.

Use this for the Blender Console Window
SetTitleMatchMode, 2
#IfWinActive, blender.exe
F4::Msgbox Blender Console Window
Use this for the Blender GUI Window
#IfWinActive, ahk_class GHOST_WindowClass
F4::Msgbox Blender GUI Window
Use this for both
SetTitleMatchMode, RegEx
#IfWinActive, i)blender [color=#008000]; lender will also work in SetTitleMatchMode 2[/color]
F4::Msgbox Blender Window
Tested in AHK basic/L and Blender2.49

hth

#6 Demian

Demian
  • Members
  • 20 posts

Posted 22 October 2012 - 04:38 PM

This works in AHK_L only, probably you have it, what do you get here:

MsgBox % A_AhkVersion

1.1.08.01

#7 Guests

  • Guests

Posted 22 October 2012 - 05:05 PM

Which means you use ahk_l which is correct as ahk_exe only works in ahk_l and not in basic.