print('main exits') def main2(stopEvent): p = subprocess.Popen('py.exe automation_notepad_py3.py') automation.Logger.WriteLine( 'call py.exe automation_notepad_py3.py'.format(p.pid), automation.ConsoleColor.DarkGreen) while True: if stopEvent.is_set(): childProcess = [] for pid, pname in automation.Win32API.EnumProcess(): ppid = automation.Win32API.GetParentProcessId(pid) if ppid == p.pid or pid == p.pid: cmd = automation.Win32API.GetProcessCommandLine(pid) childProcess.append((pid, pname, cmd)) for pid, pname, cmd in childProcess: automation.Logger.WriteLine( 'kill process: {}, {}, "{}"'.format(pid, pname, cmd), automation.ConsoleColor.Yellow) automation.Win32API.TerminateProcess(pid) break automation.Logger.WriteLine('main exits'.format(p.pid), automation.ConsoleColor.DarkGreen) if __name__ == '__main__': automation.RunWithHotKey( main, (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_1), (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_2))
def main(): automation.RunWithHotKey( { (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_1): test1, (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_2): test2 }, (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_4))
parser = argparse.ArgumentParser() parser.add_argument('main', help='exec main') parser.add_argument('-d', '--depth', type=int, default=0xFFFFFFFF, help='max expand tree depth') parser.add_argument('-r', '--root', action='store_true', help='expand from root') parser.add_argument('-p', '--print', action='store_true', help='print tree node text') args = parser.parse_args() #automation.Logger.WriteLine(str(args)) ExpandFromRoot = args.root MaxExpandDepth = args.depth PrintTree = args.print main() else: automation.Logger.WriteLine( 'move mouse to a tree control and press Ctrl+1', automation.ConsoleColor.Green) automation.RunWithHotKey( { (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_1): HotKeyFunc }, (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_2))
while True: if None != p.poll(): break if stopEvent.is_set(): childProcess = [] for pid, pname in automation.Win32API.EnumProcess(): ppid = automation.Win32API.GetParentProcessId(pid) if ppid == p.pid or pid == p.pid: cmd = automation.Win32API.GetProcessCommandLine(pid) childProcess.append((pid, pname, cmd)) for pid, pname, cmd in childProcess: automation.Logger.WriteLine( 'kill process: {}, {}, "{}"'.format(pid, pname, cmd), automation.ConsoleColor.Yellow) automation.Win32API.TerminateProcess(pid) break print('HotKeyFunc exit') if __name__ == '__main__': if 'main' in sys.argv[1:]: main() else: automation.Logger.WriteLine( 'move mouse to a tree control and press Ctrl+3', automation.ConsoleColor.Green) automation.RunWithHotKey( HotKeyFunc, (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_3), (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_4))
cmd = r'py.exe {} show {}'.format(scriptName, ' '.join(sys.argv[1:])) automation.Logger.ColorfulWriteLine('ShowWindowFunc call <Color=Green>{}</Color>'.format(cmd)) p = subprocess.Popen(cmd) while True: if None != p.poll(): break if stopEvent.is_set(): childProcess = [] for pid, pname in automation.Win32API.EnumProcess(): ppid = automation.Win32API.GetParentProcessId(pid) if ppid == p.pid or pid == p.pid: cmd = automation.Win32API.GetProcessCommandLine(pid) childProcess.append((pid, pname, cmd)) for pid, pname, cmd in childProcess: automation.Logger.WriteLine('kill process: {}, {}, "{}"'.format(pid, pname, cmd), automation.ConsoleColor.Yellow) automation.Win32API.TerminateProcess(pid) break stopEvent.wait(1) automation.Logger.WriteLine('ShowWindowFunc exit') if __name__ == '__main__': if 'hide' in sys.argv[1:]: hide() elif 'show' in sys.argv[1:]: show() else: automation.RunWithHotKey({(automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_1) : HideWindowFunc , (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_2) : ShowWindowFunc} , (automation.ModifierKey.MOD_CONTROL, automation.Keys.VK_4) )