Repository navigation
Expand file tree
/
Copy pathexample.py
More file actions
70 lines (51 loc) · 2.08 KB
/
Copy pathexample.py
File metadata and controls
70 lines (51 loc) · 2.08 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Example usage of Simple RDP client for automation.
This example demonstrates:
- Connecting to a remote Windows machine
- Moving the mouse
- Capturing screenshots
- Keyboard input (Windows key + typing)
"""
import asyncio
import logging
import os
from dotenv import load_dotenv
from rich.logging import RichHandler
from simple_rdp import RDPClient
load_dotenv()
async def main() -> None:
logging.basicConfig(level=logging.INFO, format="%(message)s", handlers=[RichHandler()])
host = os.environ.get("RDP_HOST", "")
username = os.environ.get("RDP_USER", "")
password = os.environ.get("RDP_PASS", "")
if not host or not username or not password:
print("ERROR: Set RDP_HOST, RDP_USER, RDP_PASS environment variables (or use .env file)")
return
async with RDPClient(host=host, username=username, password=password, show_wallpaper=True) as client:
print("Connected!")
# Move mouse to center and click to bring focus
await client.mouse_move(960, 540)
await asyncio.sleep(0.2)
await client.mouse_click(960, 540)
await asyncio.sleep(2)
# Take screenshot before keyboard input
img1 = await client.screenshot()
img1.save("screenshot_before.png")
print(f"Screenshot before: {img1.width}x{img1.height}")
# Press Windows key to open Start menu (scancode 0x5B = left Windows key)
print("Pressing Windows key...")
await client.send_key(0x5B) # VK_LWIN scancode
await asyncio.sleep(1.5)
# Type some text
print("Typing 'notepad'...")
await client.send_text("notepad")
await asyncio.sleep(1)
# Take screenshot after keyboard input
img2 = await client.screenshot()
img2.save("screenshot_after.png")
print(f"Screenshot after: {img2.width}x{img2.height}")
# Press Escape to close Start menu (scancode 0x01)
await client.send_key(0x01)
await asyncio.sleep(0.5)
print("Done! Check screenshot_before.png and screenshot_after.png")
if __name__ == "__main__":
asyncio.run(main())