How can I make a T9 on-screen keyboard for Windows?

Sometimes at night I like to watch movies in bed or watch TV shows on the Internet. This is convenient since my computer is near my desk, so I just rotate one of my monitors, turning off my other screen and pulling the mouse. My keyboard doesn't quite reach without redirecting the cable in a way that doesn't work when I get back to my desktop the next day. Sometimes, when I watch movies, my friends try to talk to me, and I would like to be able to talk without jumping up, twisting the monitor, moving the mouse back and sitting back in the chair.

What I would like to do is to make an on-screen keyboard for use with the mouse, but in the style of the keyboard of the T9 phone, in order to (hopefully) minimize the number of clicks and the amount of mouse movement, goals. I would like to do this in Python, as I am already familiar with this language, but I'm not sure where to start.

One thing I'm not sure about is clicking on the on-screen keyboard without stealing focus from the chat window. Can this be done? Or can an application remember the last focused control in the last focused window and send keys to it?

Also, do I need an external library to do any of this window management and send a keystroke?

Help is much appreciated, and if such a thing already exists (in any language), pointing to it, it will also be very appreciated.

, , - ​​ :)

+3
1

12 Windows, , . , .

, .

, Python, , , PyQT wxPython. ( Windows API).

, GUI PythonWin. GUI ( ), ( Window) .

, , target. , , ( ), , .

  • , ( )
  • ( , , - WM_FOCUS), , , .

, , SendMessage . , .

. .

import win32ui
import win32con
import time
from ctypes import *

PUL = POINTER(c_ulong)
class KeyBdInput(Structure):
    _fields_ = [("wVk", c_ushort),
                ("wScan", c_ushort),
                ("dwFlags", c_ulong),
                ("time", c_ulong),
                ("dwExtraInfo", PUL)]

class HardwareInput(Structure):
    _fields_ = [("uMsg", c_ulong),
                ("wParamL", c_short),
                ("wParamH", c_ushort)]

class MouseInput(Structure):
    _fields_ = [("dx", c_long),
                ("dy", c_long),
                ("mouseData", c_ulong),
                ("dwFlags", c_ulong),
                ("time",c_ulong),
                ("dwExtraInfo", PUL)]

class Input_I(Union):
    _fields_ = [("ki", KeyBdInput),
                 ("mi", MouseInput),
                 ("hi", HardwareInput)]

class Input(Structure):
    _fields_ = [("type", c_ulong),
                ("ii", Input_I)]

def send_char(char):
    FInputs = Input * 1
    extra = c_ulong(0)
    ii_ = Input_I()
    KEYEVENTF_UNICODE = 0x4
    ii_.ki = KeyBdInput( 0, ord(char), KEYEVENTF_UNICODE, 0, pointer(extra) )
    x = FInputs( ( 1, ii_ ) )
    windll.user32.SendInput(1, pointer(x), sizeof(x[0]))

if __name__ == '__main__':
    wnd = win32ui.FindWindow(None, '* Untitled - Notepad2 (Administrator)')
    type_this = 'jaraco'
    wnd.SetFocus()
    wnd.SetForegroundWindow()
    for char in type_this:
        send_char(char)

, PostMessage ( ).

.

+3

Source: https://habr.com/ru/post/1752960/


All Articles