72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
Description: <short summary of the patch>
|
||
TODO: Put a short summary on the line above and replace this paragraph
|
||
with a longer explanation of this change. Complete the meta-information
|
||
with other relevant fields (see below for details). To make it easier, the
|
||
information below has been extracted from the changelog. Adjust it or drop
|
||
it.
|
||
.
|
||
keyboard-hook (0.1.0-1) UNRELEASED; urgency=medium
|
||
.
|
||
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
|
||
Author: qiurui <qiuqiu <2653851752@qq.com>>
|
||
|
||
---
|
||
The information above should follow the Patch Tagging Guidelines, please
|
||
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
|
||
are templates for supplementary fields that you might want to add:
|
||
|
||
Origin: <vendor|upstream|other>, <url of original patch>
|
||
Bug: <url in upstream bugtracker>
|
||
Bug-Debian: https://bugs.debian.org/<bugnumber>
|
||
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
|
||
Forwarded: <no|not-needed|url proving that it has been forwarded>
|
||
Reviewed-By: <name and email of someone who approved the patch>
|
||
Last-Update: 2024-04-08
|
||
|
||
--- /dev/null
|
||
+++ keyboard-hook-0.1.0/usr/bin/server.py
|
||
@@ -0,0 +1,43 @@
|
||
+#coding:utf-8
|
||
+import os
|
||
+from socket import *
|
||
+
|
||
+NULL_CHAR = chr(0)
|
||
+
|
||
+def write_report(report):
|
||
+ with open('/dev/hidg0','rb+') as fd:
|
||
+ fd.write(report)
|
||
+
|
||
+#''代表服务器为 localhost
|
||
+myHost = ''
|
||
+#在一个非保留端口号上进行监听
|
||
+myPort = 50009
|
||
+#设置一个TCP socket对象
|
||
+sockobj = socket(AF_INET, SOCK_STREAM)
|
||
+#绑定端口号
|
||
+sockobj.bind((myHost, myPort))
|
||
+#监听,允许5个连结
|
||
+sockobj.listen(5)
|
||
+#直到进程结束时才结束循环
|
||
+while True:
|
||
+ #等待客户端连接
|
||
+ connection, address = sockobj.accept( )
|
||
+ #连接是一个新的socket
|
||
+ print ('Server connected by', address)
|
||
+ while True:
|
||
+ #读取客户端套接字的下一行
|
||
+ data = connection.recv(1024)
|
||
+ #如果没有数量的话,那么跳出循环
|
||
+ if not data: break
|
||
+ if data == "hid open":
|
||
+ os.popen('ls /sys/class/udc | xargs echo > /sys/kernel/config/usb_gadget/g1/UDC')
|
||
+ print("hid open")
|
||
+ elif data == "hid close":
|
||
+ os.popen('echo > /sys/kernel/config/usb_gadget/g1/UDC')
|
||
+ print("hid close")
|
||
+ else:
|
||
+ write_report(data)
|
||
+ #发送一个回复至客户端
|
||
+ connection.send('server => ' + data)
|
||
+ #当socket关闭时eof
|
||
+ connection.close( )
|