Search code examples
pythonpywinauto

Pywinauto throwing an MemoryError on Windows 11 but not on Windows 10


I have this code that works properly on windows 10 that I use to send text and enter keys to a specific window using pywinauto, but once i tried to use it in another system using win 11 it does not work. Here is the code:

import pywinauto
import time

boolBisCheckbox = False
def parar(eachFfox):

    global boolBisCheckbox
    if boolBisCheckbox == False:
        appname = r"\[FIREFOX " + eachFfox + r"\]"
    else:
        appname = r"\[FIREFOX " + eachFfox + r"2\]"
    handle = pywinauto.findwindows.find_window(title_re=appname)
    app = pywinauto.application.Application(backend="win32").connect(handle=handle)
    Wizard = app[appname]
    Wizard.send_keystrokes("parar")
    time.sleep(0.5)     
    Wizard.send_keystrokes("{ENTER}") 
    time.sleep(6) 
    Wizard.send_keystrokes("{ENTER}")
    time.sleep(10) 
    Wizard.send_keystrokes("{ENTER}")
input()
parar("A")

And here is the error:

Traceback (most recent call last):
  File "C:\pypy\testParar.py", line 23, in <module>
    parar("A")
  File "C:\pypy\testParar.py", line 12, in parar
    handle = pywinauto.findwindows.find_window(title_re=appname)
  File "C:\Python\lib\site-packages\pywinauto\findwindows.py", line 113, in find_window
    element = find_element(**kwargs)
  File "C:\Python\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
    elements = find_elements(**kwargs)
  File "C:\Python\lib\site-packages\pywinauto\findwindows.py", line 283, in find_elements
    elements = [elem for elem in elements if _title_match(elem)]
  File "C:\Python\lib\site-packages\pywinauto\findwindows.py", line 283, in <listcomp>
    elements = [elem for elem in elements if _title_match(elem)]
  File "C:\Python\lib\site-packages\pywinauto\findwindows.py", line 279, in _title_match
    t = w.rich_text
  File "C:\Python\lib\site-packages\pywinauto\win32_element_info.py", line 83, in rich_text
    return handleprops.text(self.handle)
  File "C:\Python\lib\site-packages\pywinauto\handleprops.py", line 92, in text
    buffer_ = create_unicode_buffer(length)
  File "C:\Python\lib\ctypes\_init_.py", line 297, in create_unicode_buffer
    buf = buftype()
MemoryError

I took the same code used in another PC running win 10 where it was working properly, and used it in win 11. The systems both have 32 Gb of Ram. I google to try to find similar questions but only found one and there was no answer to the problem.


Solution

  • I just identified the culprit, thank you so much for your insights Vasily Ryabov ! It was SteelSeriesGG.exe app for the keyboard (bloatware **** ...), even in the tray it was somehow messing with it.