Compare commits
1 Commits
master
...
directInpu
Author | SHA1 | Date | |
---|---|---|---|
d806ecf947 |
@ -1,9 +1,12 @@
|
||||
|
||||
from pywinauto.application import Application, ProcessNotFoundError
|
||||
from pywinauto.findwindows import ElementNotFoundError
|
||||
import pydirectinput
|
||||
from src import data
|
||||
from src import config
|
||||
|
||||
pydirectinput.PAUSE = 0.001
|
||||
|
||||
|
||||
def send_text(text: str) -> None:
|
||||
app = Application()
|
||||
@ -23,6 +26,37 @@ def send_text(text: str) -> None:
|
||||
win.type_keys('{ENTER}^A{DELETE}' + text + '{ENTER}', with_spaces=True, pause=config.conf['General']['after_sendkeys_key_wait'])
|
||||
|
||||
|
||||
def send_directInput(text: str) -> None:
|
||||
# with pydirectinput.KeyBdInput.__dictoffset__
|
||||
app = Application()
|
||||
try:
|
||||
app.connect(path=config.conf['General']['poe_path'])
|
||||
except ProcessNotFoundError:
|
||||
data.log.warning(f'App "{config.conf["General"]["poe_window_title"]}": "{config.conf["General"]["poe_path"]}" not found')
|
||||
return
|
||||
try:
|
||||
win = app.window(title_re=config.conf['General']['poe_window_title'])
|
||||
except ElementNotFoundError:
|
||||
data.log.warning(f'Window Title "{config.conf["General"]["poe_window_title"]}" not found')
|
||||
return
|
||||
win.SetFocus()
|
||||
win.wait(wait_for='active')
|
||||
pydirectinput.press('return')
|
||||
write_directInput(text)
|
||||
pydirectinput.press('return')
|
||||
pass
|
||||
|
||||
|
||||
def write_directInput(text: str):
|
||||
for c in text:
|
||||
if c.isupper():
|
||||
pydirectinput.keyDown('shift')
|
||||
pydirectinput.press(c.lower())
|
||||
pydirectinput.keyUp('shift')
|
||||
else:
|
||||
pydirectinput.press(c)
|
||||
|
||||
|
||||
def escape_mods(text: str) -> str:
|
||||
text = text.replace('%', '{%}')
|
||||
text = text.replace('+', '{+}')
|
||||
|
@ -1,6 +1,15 @@
|
||||
from src import sendkeys
|
||||
from src import config
|
||||
from src import data
|
||||
import win32api
|
||||
import win32gui
|
||||
import win32con
|
||||
from time import sleep
|
||||
|
||||
|
||||
def test_send_direct():
|
||||
config.read_config(r'config.yaml')
|
||||
sendkeys.send_directInput('Hello World')
|
||||
|
||||
|
||||
def test_sendkeys():
|
||||
@ -74,3 +83,20 @@ def test_ty_wo_trade():
|
||||
text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, how are you doing? '
|
||||
message = data.Message.from_text(text)
|
||||
sendkeys.send_to_format('ty', message)
|
||||
|
||||
|
||||
def test_win31_api():
|
||||
hwndMain = win32gui.FindWindow(None, "cmd")
|
||||
hwndChild = win32gui.GetWindow(hwndMain, win32con.GW_CHILD)
|
||||
while(True):
|
||||
# [hwndChild] this is the Unique ID of the sub/child application/proccess
|
||||
# [win32con.WM_CHAR] This sets what PostMessage Expects for input theres KeyDown and KeyUp as well
|
||||
# [0x44] hex code for D
|
||||
# [0]No clue, good luck!
|
||||
# temp = win32api.PostMessage(hwndChild, win32con.WM_CHAR, 0x44, 0) returns key sent
|
||||
temp = win32api.PostMessage(hwndChild, win32con.WM_CHAR, 0x44, 0)
|
||||
|
||||
# print(temp) prints the returned value of temp, into the console
|
||||
print(temp)
|
||||
# sleep(1) this waits 1 second before looping through again
|
||||
sleep(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user