Exemplo n.º 1
0
def controll_PC(index, configObj):
    # print(configObj['gesture_list'][index]['isopen'])
    if index == 5:
        return
    action = []
    handle = win32gui.GetForegroundWindow()
    threadpid, procpid = win32process.GetWindowThreadProcessId(handle)
    # print(procpid) 快速切换句柄可能错误
    activeApp = 'cannot get path'
    try:
        mypyproc = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, False,
                                        procpid)
        activeApp = win32process.GetModuleFileNameEx(mypyproc, 0)
    except Exception:
        pass

    for app in configObj['program_list']:
        if app['name'] == '默认设置' and app['gesture_list'][index]['isopen']:
            action = app['gesture_list'][index]['action']
        elif activeApp == app['path'] and app['gesture_list'][index]['isopen']:
            action = app['gesture_list'][index]['action']
            break
    for i in action:
        k.press_key(keyMap.get(i))
        print(i)
    for i in action:
        k.release_key(keyMap.get(i))
Exemplo n.º 2
0
def close_window_by_name(name):
    try:
        target_hwnd = win32gui.FindWindow(None, name)
        tid, pid = win32process.GetWindowThreadProcessId(target_hwnd)
        os.kill(pid, signal.SIGTERM)
    except:
        pass
Exemplo n.º 3
0
 def _window_enum_callback(self, hwnd, wildcard):
     tid, pid = win32process.GetWindowThreadProcessId(hwnd)
     title = win32gui.GetWindowText(hwnd)
     if (self.lock_pid == pid) and (title == wildcard):
         win32gui.ShowWindow(hwnd, 9)
         win32gui.SetForegroundWindow(hwnd)
         win32gui.SetActiveWindow(hwnd)
 def start(self):
     # A full list of Excel's properties may be found here:
     # https://docs.microsoft.com/en-us/office/vba/api/excel.application(object)
     self.excel = win32com.client.DispatchEx('Excel.Application')
     _, self.pid = win32process.GetWindowThreadProcessId(self.excel.Hwnd)
     self.excel.ScreenUpdating = False
     self.excel.DisplayAlerts = True
     self.excel.Visible = False
Exemplo n.º 5
0
 def thread_id(self) -> int:
     """
     窗口所在线程id
     @property {int}
     """
     _thread_id, _process_id = win32process.GetWindowThreadProcessId(
         self.handle)
     return _thread_id
Exemplo n.º 6
0
def window_enum_handler(hwnd, handler_param):
    window_process_id = win32process.GetWindowThreadProcessId(hwnd)[1]
    for process in handler_param["processes"]:
        if process.pid == window_process_id:
            owner_window_handle = win32gui.GetWindow(hwnd, GW_OWNER)
            owner_window_is_visible = win32gui.IsWindowVisible(
                owner_window_handle)
            if owner_window_is_visible:
                win32gui.ShowWindow(owner_window_handle,
                                    handler_param["operation"])
Exemplo n.º 7
0
def getAppName():
    global afk_state
    try:
        _, processID = win32process.GetWindowThreadProcessId(win32gui.GetForegroundWindow())
        app_name = psutil.Process(processID).name()
        return app_name
    except:
        # This tends to happen if the computer is going to sleep, so afk is safe to assume -- 
        # even it it's some other reason, the afk will be undone too quickly to do damage
        afk_state = True
        return None
Exemplo n.º 8
0
	def callback(hwnd, hwnds):
		if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
			if pid_text is not None:
				text = win32gui.GetWindowText(hwnd)
				if text.find(pid_text) >= 0:
					hwnds.append(hwnd)
			else:
				_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
				if found_pid == pid:
					hwnds.append(hwnd)
		return True
Exemplo n.º 9
0
def offpid(hwnd):
    if is_window_legal(hwnd):
        thread_id, process_id = win32process.GetWindowThreadProcessId(hwnd)
        try:
            process = util.Process(process_id)
            process.kill()
        except:
            pass
        else:
            i = find_window(hwnd)
            if i is not None:
                del hwnd_title[i]
        updatewindow(hwnd)
Exemplo n.º 10
0
def proces():
    i = 0
    kut = ""
    #while i <= 1:

    time.sleep(1)

    w = win32gui

    w.GetWindowText(w.GetForegroundWindow())

    pid = win32process.GetWindowThreadProcessId(w.GetForegroundWindow())

    kut = psutil.Process(pid[-1]).name()
    print(kut)
    if (kut == "vlc.exe"):
        listen()
    else:
        proces()
Exemplo n.º 11
0
 def callback(hwnd, hwnds):
     _, found_pid = win32process.GetWindowThreadProcessId(hwnd)
     if found_pid == self._pid:
         hwnds.append(hwnd)
     return True
import ctypes

kernel32 = ctypes.windll.LoadLibrary(r"C:/Windows/System32/kernel32.dll")


def GetAddress(handle, BaseAddress=0x00197f1c, offset=[0x5578]):
    value = ctypes.c_long()
    kernel32.ReadProcessMemory(int(handle), BaseAddress, ctypes.byref(value),
                               4, None)
    for i in range(len(offset) - 1):
        kernel32.ReadProcessMemory(int(handle), value.value + offset[i],
                                   ctypes.byref(value), 4, None)
    return value.value + offset[len(offset) - 1]


hwnd = win32gui.FindWindow("MainWindow", "Plants vs. Zombies")
pid = win32process.GetWindowThreadProcessId(hwnd)[1]
handle = win32api.OpenProcess(0x1F0FFF, False, pid)

currentSun = ctypes.c_long()
changeSun = ctypes.c_long()

while True:
    address = GetAddress(handle)
    kernel32.ReadProcessMemory(int(handle), address, ctypes.byref(currentSun),
                               4, None)
    print("{}:{}".format("当前阳光", currentSun.value))
    changeSun.value = int(input("要修改成多少:"))
    kernel32.WriteProcessMemory(int(handle), address, ctypes.byref(changeSun),
                                4, None)
Exemplo n.º 13
0
 def active_window_process_name(self):
     pid = win32process.GetWindowThreadProcessId(
         win32gui.GetForegroundWindow(
         ))  #This produces a list of PIDs active window relates to
     #pid[-1] is the most likely to survive last longer
     return psutil.Process(pid[-1]).name()
Exemplo n.º 14
0
 def add_window_process_ids(self, hwnd, window_process_ids):
     window_text = win32gui.GetWindowText(hwnd).strip()
     if window_text == "":
         return
     window_process_id = win32process.GetWindowThreadProcessId(hwnd)[1]
     window_process_ids.add(window_process_id)
Exemplo n.º 15
0
 def getHwnd(hwnd, procid):
     if procid in win32process.GetWindowThreadProcessId(hwnd):
         if win32gui.IsWindowVisible(hwnd):
             self.__HWND = hwnd
Exemplo n.º 16
0
def hideWin(hwnd,pid):
	if win32process.GetWindowThreadProcessId(hwnd)[1] == pid:
		ShowWindow(hwnd, 0)
Exemplo n.º 17
0
 def callback(hwnd, pid):
     if win32process.GetWindowThreadProcessId(hwnd)[1] == pid:
         win32gui.ShowWindow(hwnd, 0)
Exemplo n.º 18
0
def get_winprocess(hwnd):
    thread_id, process_id = win32process.GetWindowThreadProcessId(hwnd)
    process = util.Process(process_id)
    return process_id, process.name()
Exemplo n.º 19
0
def active_window_process_name():
    try:
        pid = win32process.GetWindowThreadProcessId(win32gui.GetForegroundWindow())
        return(psutil.Process(pid[-1]).name())
    except:
        pass
Exemplo n.º 20
0
def callback2(hwnd, pid):
    if win32process.GetWindowThreadProcessId(hwnd)[1] == pid:
        # hide window
        win32gui.ShowWindow(hwnd, 1)