Add heartbeat event
This commit is contained in:
parent
db13ba9c34
commit
b3cd983229
11
README.txt
11
README.txt
@ -6,18 +6,21 @@ A key-press event would look like this:
|
||||
0 0 0 0 0 0 0 0 0 1 5
|
||||
* 9 padding nulls, 1 = event id (keyboard), 5 = button
|
||||
|
||||
KEYBOARD (1):
|
||||
HEARTBEAT (1):
|
||||
* no data
|
||||
|
||||
KEYBOARD (2):
|
||||
* uint8 pressed: If the button is pressed (1) or released (0)
|
||||
* uint8 keycode: The keycode of the button
|
||||
|
||||
MOUSE_MOVE (2):
|
||||
MOUSE_MOVE (3):
|
||||
* int32 x: Relative X movement (negative numbers move to the left)
|
||||
* int32 y: Relative Y movement (negative numbers move to the top)
|
||||
|
||||
MOUSE_PRESS (3):
|
||||
MOUSE_PRESS (4):
|
||||
* uint8 pressed: If the button is pressed (1) or released (0)
|
||||
* uint8 keycode: The keycode of the button
|
||||
|
||||
MOUSE_WHEEL (4):
|
||||
MOUSE_WHEEL (5):
|
||||
* int32 x: Wheel X roll (negative numbers move to the left)
|
||||
* int32 y: Wheel Y roll (negative numbers move to the top)
|
||||
|
@ -5,10 +5,11 @@ import sys
|
||||
import os
|
||||
|
||||
def main():
|
||||
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0)
|
||||
pressedKeys = {}
|
||||
grabbed = False
|
||||
padding = b'\x00' * 9
|
||||
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0)
|
||||
frame = 0
|
||||
|
||||
window = sdl2.SDL_CreateWindow("input-to-pipe".encode("utf-8"),sdl2.SDL_WINDOWPOS_UNDEFINED,sdl2.SDL_WINDOWPOS_UNDEFINED,50,50,0)
|
||||
while True:
|
||||
@ -37,7 +38,7 @@ def main():
|
||||
|
||||
unbufferedStdout.write(
|
||||
padding+
|
||||
(1).to_bytes(1,"little")+
|
||||
(2).to_bytes(1,"little")+
|
||||
down.to_bytes(1,"little")+
|
||||
keycode.to_bytes(1,"little")
|
||||
)
|
||||
@ -48,7 +49,7 @@ def main():
|
||||
y = event.motion.yrel
|
||||
unbufferedStdout.write(
|
||||
padding+
|
||||
(2).to_bytes(1,"little")+
|
||||
(3).to_bytes(1,"little")+
|
||||
x.to_bytes(4,"little",signed=True)+
|
||||
y.to_bytes(4,"little",signed=True)
|
||||
)
|
||||
@ -58,7 +59,7 @@ def main():
|
||||
keycode = event.button.button
|
||||
unbufferedStdout.write(
|
||||
padding+
|
||||
(3).to_bytes(1,"little")+
|
||||
(4).to_bytes(1,"little")+
|
||||
down.to_bytes(1,"little")+
|
||||
keycode.to_bytes(1,"little")
|
||||
)
|
||||
@ -68,13 +69,20 @@ def main():
|
||||
y = event.wheel.y
|
||||
unbufferedStdout.write(
|
||||
padding+
|
||||
(4).to_bytes(1,"little")+
|
||||
(5).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)
|
||||
frame += 1
|
||||
if frame >= 100:
|
||||
frame = 0
|
||||
unbufferedStdout.write(
|
||||
padding+
|
||||
(1).to_bytes(1,"little")
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user