Instead of running scripts with pyautogui or pywinauto (both python libraries) is there any way of programing a mouse in a "native" way, like, outside of the OS (undetectable)

I remember once saw a logitech mouse that was able to add scripts, but I am not sure what are the limitations/posibilities

Would be cool the same for a keyboard, any ideas?