forked from nyaoouo/FFxivPythonTrigger2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
54 lines (44 loc) · 1.5 KB
/
Copy path__init__.py
File metadata and controls
54 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ctypes.wintypes
import os
from aiohttp import web
import time
from FFxivPythonTrigger import PluginBase, api, window
import win32con
class KeyApi:
@staticmethod
def key_down(key_code: int):
ctypes.windll.user32.SendMessageA(window.CURRENT_HWND, win32con.WM_KEYDOWN, key_code, 0)
@staticmethod
def key_up(key_code: int):
ctypes.windll.user32.SendMessageA(window.CURRENT_HWND, win32con.WM_KEYUP, key_code, 0)
@staticmethod
def key_press(key_code: int, time_ms: int = 10):
KeyApi.key_down(key_code)
time.sleep(time_ms / 1000)
KeyApi.key_up(key_code)
class SendKeys(PluginBase):
name = "SendKeys"
git_repo = 'nyaoouo/FFxivPythonTrigger2'
repo_path = 'plugins/SendKeys'
hash_path = os.path.dirname(__file__)
async def text_command_handler(self, request: web.Request):
try:
code = int(await request.text())
KeyApi.key_press(code)
except TypeError:
return web.json_response({
'msg': 'failed',
'rtn': 'type error'
})
else:
return web.json_response({
'msg': 'success',
'rtn': code
})
def __init__(self):
super().__init__()
self.api_class = KeyApi()
self.register_api("SendKeys", self.api_class)
api.HttpApi.register_post_route('sendkey', self.text_command_handler)
def _onunload(self):
api.HttpApi.unregister_post_route('sendkey')