import ctypes
import System
from ctypes import windll
last_id = 0
for i in range(50):
System.Threading.Thread.Sleep(50)
hwnd = windll.user32.GetForegroundWindow()
pid = ctypes.c_ulong()
windll.user32.GetWindowThreadProcessId(hwnd,ctypes.byref(pid))
p = System.Diagnostics.Process.GetProcessById(pid.value)
if last_id != pid.value:
print p.MainWindowTitle
last_id = pid.value
I wonder how I can repay you!
See, the problem is that I have looked at that same page from the link, but none of what’s in there makes enough sense for me so I can use it in any way.
Now I’ll see if I can implement this so I can release the control over the mouse if Rhino is not active.
I have tried the code now, and it works, but not reliable. For some reason if I wait for a while, when the python editor is active, and then run it, it sometimes returns a blank.
Sometimes if I run it and toggle back and forth between Rhino and another app then it returns both, as it should, and other times it only returns “the other app” and returns Rhino as a blank. Without an apparent logic to it.
Well, I’ll let it rest for a while now and look at it tomorrow.
Agan THANK YOU SO MUCH for the help!!!
Second Edit:
It seems to work great when in a plugin!
The script editor might have been the thing that caused the blank return.
The plugin now terminates the moment Rhino is no longer active.