示例#1
0
def is_process_running(name=None, path=None):  # Only ascii API is Implemented!
    """
  @param* name  unicode
  @param* path  unicode
  @return  bool
  """
    if name:
        name = name.lower()
        for p in psutil.process_iter():
            if p.pid and p.is_running(
            ):  # pid == 0 will raise access denied exception on Mac
                try:
                    it = u(
                        p.name
                    )  # system processes raise access denied exception on Windows 7
                except:
                    continue
                if name == it.lower():
                    return True
    if path:
        np = osutil.normalize_path(path)
        for p in psutil.process_iter():
            if p.pid and p.is_running(
            ):  # pid == 0 will raise access denied exception on Mac
                try:
                    it = u(
                        p.exe
                    )  # system processes raise access denied exception on Windows 7
                except:
                    continue
                if path == osutil.normalize_path(it):
                    return True
    return False
示例#2
0
def iterprocess():
    """Generator of candidate game process
  @yield  Process

  Implemented using psutil. Using WMI is more efficient, but less portable.
  See: http://www.blog.pythonlibrary.org/2010/10/03/how-to-find-and-list-all-running-processes-with-python/
  """

    for p in psutil.process_iter():
        if (p.pid and  # pid == 0 will raise access denied exception on Mac
                p.is_running() and
                p.pid != PID and get_process_active_window(p.pid)):
            try:
                path = u(
                    p.exe
                )  # system processes raise access denied exception on Windows 7
            except:
                continue
            name = u(p.name)
            if is_blocked_process_name(name) or is_blocked_process_path(path):
                continue
            pid = p.pid
            if '?' in path:  # Japanese characters
                path = skwin.get_process_path(pid)
                name = os.path.basename(path)
            yield Process(pid=pid, name=name, path=path)
示例#3
0
    def _onMousePress(self, event):
      """
      @param  event  pyHook.HookManager.MouseEvent
      @return  bool  Whether pass the event to other handlers
      """
      dprint("enter")
      if self.active:
        #print "---"
        #print "  message name:", event.MessageName
        #print "  message (MSG):", event.Message
        #print "  event time:", event.Time
        #print "  window (HWND):", event.Window
        #print "  window title:", event.WindowName
        #print "  position:", event.Position
        #print "  wheel:", event.Wheel
        #print "  injected:", event.Injected
        #print "---"

        hwnd = event.Window
        title = u(event.WindowName)
        if hwnd:
          dprint("found hwnd")
          self._clickWindow(hwnd, title)
          dprint("leave: active")
          return False # eat the event
      dprint("leave: not active")
      return True # return True to pass the event to other handlers
示例#4
0
    def _startSession(self):
        """
    @return  bool
    @raise  WindowsError, AttributeError

    Guessed:
    int __stdcall StartSession(LPCWSTR path, DWORD bufferStart, DWORD bufferStop, LPCWSTR pathName)

    path must be unicode instead of str.
    start and stop are a chunk of buffer, size = 0x40

    Debugging method: debug SeniorTranslate for StartSession
       054FFF10   0041FC12  RETURN to SeniorTr.0041FC12
       054FFF14   01554F98  UNICODE "C:\tmp\FASTAIT_PERSONAL\GTS\JapaneseSChinese\DCT"
       054FFF18   01550C60  ; pointer to a chunk of zeros
       054FFF1C   01550C20  ; pointer to 0x00
       054FFF20   01550C40  UNICODE "DCT"
       054FFF24   9A9C60FE
       054FFF28   015593A0
       054FFF2C   054FFF88
       054FFF30   00000488
       054FFF34   01550C40  UNICODE "DCT"
       054FFF38   01550C20
       054FFF3C   01550C60
       054FFF40   01554F98  UNICODE "C:\tmp\FASTAIT_PERSONAL\GTS\JapaneseSChinese\DCT"
       054FFF44   054FFF7C  Pointer to next SEH record
       054FFF48   00425D84  SE handler
       054FFF4C   00000003
       054FFF50   0040C48B  RETURN to SeniorTr.0040C48B from SeniorTr.0041FB40
    """
        dicpath = u(os.path.join(self.dllDirectory, DEFAULT_DIC))
        if not dicpath or not os.path.exists(dicpath):
            dwarn("gts dic directory does not exist")
            return False
        buf = self.sessionBuffer
        start = ctypes.addressof(buf)
        stop = start + SESSION_BUFFER_SIZE
        ok = 0 == self.dll.StartSession(dicpath, start, stop, DEFAULT_DIC)
        dprint("ok =", ok)
        return ok
示例#5
0
def get():
    """
  @return  [{kw}] not None
  """
    #REG = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens"

    ret = []
    import _winreg
    for (hk, path) in (
        (_winreg.HKEY_LOCAL_MACHINE, SAPI_HKLM_PATH),
        (_winreg.HKEY_CURRENT_USER, SAPI_HKCU_PATH),
    ):
        try:
            with _winreg.ConnectRegistry(None,
                                         hk) as reg:  # None = computer_name
                with _winreg.OpenKey(reg, path) as rootkey:
                    nsubkeys = _winreg.QueryInfoKey(rootkey)[0]
                    for i in xrange(nsubkeys):
                        try:
                            voicekeyname = _winreg.EnumKey(rootkey, i)
                            dprint("sapi key: %s" % voicekeyname)
                            with _winreg.OpenKey(rootkey,
                                                 voicekeyname) as voicekey:
                                clsid = _winreg.QueryValueEx(
                                    voicekey, 'CLSID')[0]
                                try:
                                    location = _winreg.QueryValueEx(
                                        voicekey, 'VoiceData')[0]
                                except WindowsError:
                                    try:
                                        location = _winreg.QueryValueEx(
                                            voicekey, 'VoicePath')[0]
                                    except WindowsError:
                                        location = ""
                                with _winreg.OpenKey(voicekey,
                                                     'Attributes') as attrkey:
                                    # ja: "411", en_US: "409:9"
                                    language = _winreg.QueryValueEx(
                                        attrkey, 'Language')[0]
                                    lcid = long(
                                        language.split(';', 1)[0], 16
                                    )  # such as '411;9' where 411 => 0x411
                                    age = _winreg.QueryValueEx(attrkey,
                                                               'Age')[0]
                                    gender = _winreg.QueryValueEx(
                                        attrkey, 'Gender')[0]
                                    name = _winreg.QueryValueEx(
                                        attrkey, 'Name')[0]
                                    vendor = _winreg.QueryValueEx(
                                        attrkey, 'Vendor')[0]
                                    uk = u(
                                        voicekeyname
                                    )  # convert to u8 using native encoding
                                    if uk:
                                        ret.append({
                                            'key':
                                            uk,
                                            'clsid':
                                            clsid,  # str
                                            'location':
                                            u(location),  # unicode
                                            'age':
                                            age,  # str
                                            #'name': u(name), # unicode
                                            'name':
                                            name,  # use str instead
                                            'vendor':
                                            u(vendor),  # unicode
                                            'lcid':
                                            lcid,  # long
                                            'language':
                                            _parselang(lcid),  #
                                            'gender':
                                            _parsegender(gender),  #
                                        })
                                    else:
                                        dwarn(
                                            "failed to convert registry key to unicode: %s"
                                            % voicekeyname)
                        except WindowsError, e:
                            dwarn(e)
                        except (ValueError, TypeError
                                ), e:  # failed to convert lcid to long
                            dwarn(e)