Initial commit

This commit is contained in:
Fierelier 2024-07-13 06:36:27 +02:00
commit 26545aa6ef
2 changed files with 89 additions and 0 deletions

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2024
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

80
input-to-pipe Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env python3
import sdl2
import sdl2.ext
import sys
import os
def main():
pressedKeys = {}
grabbed = False
padding = b'\x00' * 9
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0)
window = sdl2.SDL_CreateWindow("input-to-pipe".encode("utf-8"),sdl2.SDL_WINDOWPOS_UNDEFINED,sdl2.SDL_WINDOWPOS_UNDEFINED,50,50,0)
while True:
events = sdl2.ext.get_events()
for event in events:
if event.type == sdl2.SDL_QUIT:
return
# KEYBOARD
if event.type in [sdl2.SDL_KEYDOWN,sdl2.SDL_KEYUP]:
down = (event.type == sdl2.SDL_KEYDOWN)
keycode = event.key.keysym.scancode
if down:
pressedKeys[keycode] = True
else:
del pressedKeys[keycode]
if (
224 in pressedKeys and
226 in pressedKeys and
11 in pressedKeys
):
grabbed = (not grabbed)
sdl2.SDL_SetRelativeMouseMode(grabbed)
sdl2.SDL_SetWindowKeyboardGrab(window,grabbed)
unbufferedStdout.write(
padding+
(1).to_bytes(1,"little")+
down.to_bytes(1,"little")+
keycode.to_bytes(1,"little")
)
# MOUSE
if event.type == sdl2.SDL_MOUSEMOTION:
x = event.motion.xrel
y = event.motion.yrel
unbufferedStdout.write(
padding+
(2).to_bytes(1,"little")+
x.to_bytes(4,"little",signed=True)+
y.to_bytes(4,"little",signed=True)
)
if event.type in [sdl2.SDL_MOUSEBUTTONDOWN,sdl2.SDL_MOUSEBUTTONUP]:
down = (event.type == sdl2.SDL_MOUSEBUTTONDOWN)
keycode = event.button.button
unbufferedStdout.write(
padding+
(3).to_bytes(1,"little")+
down.to_bytes(1,"little")+
keycode.to_bytes(1,"little")
)
if event.type == sdl2.SDL_MOUSEWHEEL:
x = event.wheel.x
y = event.wheel.y
unbufferedStdout.write(
padding+
(4).to_bytes(1,"little")+
x.to_bytes(4,"little",signed=True)+
y.to_bytes(4,"little",signed=True)
)
#sdl2.SDL_UpdateWindowSurface(window)
sdl2.SDL_Delay(16)
if __name__ == "__main__":
main()