kennyhml/pyinterception

alt+prtsc

Closed this issue · 5 comments

zinkq commented

Hi!

Thanks for responding to my last question. You helped me a lot!

I'm wondering how can I simulate alt+prtsc, I've tried:
with interception.hold_key("altleft"): interception.press("printscreen")
Well, I want to click alt + prtscn, so it screenshots the active window, not the whole screen - as printscreen does.

Do you have any idea? Also, when the printscreen is pressed it is shown as num* key, but works correctly without alt combination.
image
The screen from the keyboard test, Prt Sc is a real key while num* is the simulated one.

Hi @zinkq,

the reason you may be seeing the printscreen come out as another key is because the program uses scancodes which may vary between keyboard layouts.

You can use

import interception

interception.listen_to_keyboard()

to get the real keycode of the key youre looking for

zinkq commented

But the problem is that printscreen works fine until I try to simulate alt+printscreen sequence,

while listening to keyboard, the printscreen key shows as:

Received stroke KeyStroke(code=42, state=2, information=0) on keyboard device 7
Received stroke KeyStroke(code=55, state=2, information=0) on keyboard device 7
Received stroke KeyStroke(code=55, state=3, information=0) on keyboard device 7
Received stroke KeyStroke(code=42, state=3, information=0) on keyboard device 7

So, how I can send keys using the default scancodes instead of string?
And also, how can I perform alt+printscreen sequence, so it will take screenshot of active window only.

hmm I wonder why youre getting two different codes. May be a weird quirk with the key?

You can change the scancode in the _keycodes.py fille

zinkq commented

Thanks for replying, though.

For anyone who has been struggling with the same issue - windows provides different scancode for alt+prtsc combination.
alt+prtsc = 0x54
alt = 0x38

so your _keycodes.py should look like:

"altprtsc": 0x54, //or any other keyname
"alt": 0x38,

and your code should look like that:

with interception.hold_key("alt"):
    interception.press("altprtsc")

That allows you to screenshot an active window, so you don't have to mess with it anymore. It holds alt(0x38) and then presses (0x54 - the scancode which allows you to perform alt+prtsc).

Thanks for letting me know! I'll fix it at my earliest convenience.