Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No direct pasting into last active application on Windows 11 #21

Open
MarkL1969 opened this issue Feb 11, 2024 · 2 comments
Open

No direct pasting into last active application on Windows 11 #21

MarkL1969 opened this issue Feb 11, 2024 · 2 comments

Comments

@MarkL1969
Copy link

Describe the bug
On Windows, when clicking on an emoji, it should be inserted into the last active window / input field bevor opening efck - but it doesn't.

To Reproduce
Steps to reproduce the behavior:

  1. Open notepad (or any other application / input line)
  2. Click strg+alt+.
  3. click on an emoji in efck
  4. efck closes, the focus returns to the previously active windows but no emoji is inserted

Expected behavior
The clicked emoji should be inserted in the last active window / input field.

Versions
Specify versions:
OS: Windows 11 Pro, 10.0.22631 Build 22631
Qt:
EFCK: 6.1.7601.17514

When activating "Force clipboard" the selected emoji is placed into the clipboard. But direct pasting would be much nicer...

@kernc
Copy link
Member

kernc commented Feb 12, 2024

Thanks for the issue report!

This worked for me on Windows 10 and was last tested working on Windows Server 2022. Maybe something broke with Win 11.

Unfortunately, I don't currently have Windows 11 to test/debug myself. If you know a little of Python and you're interested in helping out, this is the relevant part that types out characters on Windows:

efck/efck/output.py

Lines 131 to 196 in b695b8a

def _type_windos(text):
import ctypes
from ctypes.wintypes import DWORD, LONG, WORD, PULONG
# God help us!
# Adapted from:
# https://github.com/Drov3r/Forza/blob/b3e489c1447f2fdc46081e053008aaa1ab77a12a/control.py#L63
# https://stackoverflow.com/questions/22291282/using-sendinput-to-send-unicode-characters-beyond-uffff
class KeyboardInput(ctypes.Structure):
_fields_ = [("wVk", WORD),
("wScan", WORD),
("dwFlags", DWORD),
("time", DWORD),
("dwExtraInfo", PULONG)]
class HardwareInput(ctypes.Structure):
_fields_ = [("uMsg", DWORD),
("wParamL", WORD),
("wParamH", WORD)]
class MouseInput(ctypes.Structure):
_fields_ = [("dx", LONG),
("dy", LONG),
("mouseData", DWORD),
("dwFlags", DWORD),
("time", DWORD),
("dwExtraInfo", PULONG)]
class Input_I(ctypes.Union):
_fields_ = [("ki", KeyboardInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", DWORD),
("ii", Input_I)]
def as_wchars(ch):
assert len(ch) == 1, (ch, len(ch))
bytes = ch.encode('utf-16be')
while bytes:
yield int.from_bytes(bytes[:2], 'big')
bytes = bytes[2:]
TYPE_KEYBOARD_INPUT = 1
KEYEVENTF_UNICODE = 0x4
KEYEVENTF_KEYUP = 0x2
KEYEVENTF_KEYDOWN = 0
inputs = []
for ch in text:
for wch in as_wchars(ch):
for flag in (KEYEVENTF_KEYDOWN,
KEYEVENTF_KEYUP):
input = Input(TYPE_KEYBOARD_INPUT)
# XXX: Assuming ctypes.Structure is memset to 0 at initialization?
input.ii.ki.wScan = WORD(wch)
input.ii.ki.dwFlags = KEYEVENTF_UNICODE | flag
inputs.append(input)
inputs = (Input * len(inputs))(*inputs)
n = ctypes.windll.user32.SendInput(len(inputs), inputs, ctypes.sizeof(Input))
assert n == len(inputs)
return 0

Can you check whether the function types out anything when used standalone in a Python interpreter? E.g.

>>> ...  # paste the function body with all its required imports
>>> _type_windos('test')
>>> # should type "test" here

Alternatively, this had proven before to be the flaky part:

efck/efck/gui.py

Lines 318 to 327 in b695b8a

# Hide our app window before typing
self.close()
# Give WM time to switch active window / focus
QApplication.instance().processEvents()
QThread.currentThread().msleep(self.WM_SWITCH_ACTIVE_WINDOW_SLEEP_MS)
QApplication.instance().processEvents()
tab.activated(force_clipboard=force_clipboard)
QApplication.instance().quit()

Maybe see if changing/increasing WM_SWITCH_ACTIVE_WINDOW_SLEEP_MS duration fixes anything.

You can find the source code files in the designated Program Files subdirectory in the base_library.zip file. Then again, the built Windows EXE is not the best distribution to debug/develop on ...

@MarkL1969
Copy link
Author

sorry but I can only use the pre-build versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants