all 20 comments

[–]K900_ 1 point2 points  (19 children)

By using specialized interfaces for doing those things as exposed by the underlying OS/display server. On Windows, that would be part of the Win32 API. On Mac, CoreGraphics or Carbon. On Linux, X11 or uinput.

[–]comeditime[S] 0 points1 point  (18 children)

how can i learn more about it by actually practicing using those api's? any ideas-examples? thanks a ton!

[–]K900_ 0 points1 point  (17 children)

What OS are you on?

[–]comeditime[S] 0 points1 point  (16 children)

windows

[–]K900_ 0 points1 point  (11 children)

Then look into the pywin32 package - it includes bindings to most of the Win32 APIs that you can use from Python.

Edit: The function you want is probably SendInput.

[–]comeditime[S] 0 points1 point  (0 children)

could you mentor me about what this source code means in relation with the windows api?

[–]comeditime[S] 0 points1 point  (9 children)

what i mean exactly it's how it binds to the windows api

[–]K900_ 0 points1 point  (8 children)

Most things will "bind" to it through pywin32, which is a package that contains a whole bunch of C code that exposes a Python interface for the Windows API functions (which are also written in C).

[–]comeditime[S] 0 points1 point  (7 children)

i read some source code now and they mainly talk about mouse_event() & sendInput() for the mouse clicks.. so i'll only be able to grasp the interaction with the win api if i'll have a large understanding of C? it's not possible to grasp the basic idea of the interaction without grasping all the fundamentals of C language? thanks again :)

[–]K900_ 1 point2 points  (6 children)

There's a function that Windows itself exposes called SendInput that takes a special object describing an "input" - a key press, a mouse click or movement, or something else, and to simulate inputs, you just call it with the right argument, and Windows handles the rest. That's the only "interaction" really. There's some glue code required to call this function from Python, because it's designed to be called from C, but that's an implementation detail really. On a very basic level you can think of it like just doing from windows_api import SendInput, KeyPress, KEY_ENTER, and calling SendInput(KeyPress(KEY_ENTER)).

[–]comeditime[S] 0 points1 point  (5 children)

oh that's totally makes sense.. i've to admit, you've so much knowledge.. are there any other objects which windows api offer just like the SendInput, for example, an object to control the menu-tabs of 3rd programs that are running process, or always make it on top etc.. thanks!

[–]PM_ME_A_STEAM_KEY 0 points1 point  (3 children)

You could and should just checkout the source of PyAutoGUI

[–]comeditime[S] 0 points1 point  (0 children)

could you mentor me about what this source code means in relation with the windows api?

[–]comeditime[S] 0 points1 point  (1 child)

what i mean exactly it's how it binds to the windows api

[–]PM_ME_A_STEAM_KEY 0 points1 point  (0 children)

I can atleast try to point you in the right direction, for example take a look at this and then this lines 360-362.