xdotool not really what I'd like, but it's better than nothing
Well, (probably) you could improve it, by not using external process: looks like there's `libxdo[-dev]` packages,
which (I think) actually contain needed api, if you know how to use C <-> Pascal bindings:
/usr/include/xdo.h - you need to translate header to Pascal (not all, but just few actually required functions, maybe some dependent structures)
/usr/lib/x86_64-linux-gnu/libxdo.so - you need to link it.