Mike
Mike

Reputation: 11

Setting xy position of Popen object and closing object

I can open the OSK keyboard for windows in Python using Popen but cannot set the xy position or close it on event. I have tried to set the xy position of it adapting the answer from this:

`` Changing the position of the console window with Python (Windows)

Any help would be much appreciated. Thanks

The following is the code I used - I was expecting the position to be set when the keyboard is called. Also I expected the osk keyboard to be closed using the .terminate() command when called.

import time
import subprocess
from subprocess import Popen
import win32gui

appname = 'osk'
xpos = 50
ypos = 400
width = 800
length = 600

def enumHandler(hwnd, lParam):
    if win32gui.IsWindowVisible(hwnd):
        if appname in win32gui.GetWindowText(hwnd):
            win32gui.MoveWindow(hwnd, xpos, ypos, width, length, True)

def openKeyboard(event):
    global pro
    pro = subprocess.Popen("osk", stdout= subprocess.PIPE, shell=True)
    time.sleep(10)
    win32gui.EnumWindows(enumHandler, None)

def closeKeyboard(event):
    pro.terminate()

Upvotes: 1

Views: 23

Answers (0)

Related Questions