Skip to content

Commit 607c5fd

Browse files
Add remote kit, v5.3
1 parent bec35d1 commit 607c5fd

File tree

3 files changed

+337
-3
lines changed

3 files changed

+337
-3
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
# Links
1616

17-
- **Have some query or suggestions or want to become a beta tester, join our discord server - [Discord invite link](https://discord.gg/62Yf5mushu)**
18-
- **Help us test an upcoming feature - [here](https://pywhatkit.herokuapp.com/remote-kit)**
17+
- **Join our discord server - https://discord.gg/62Yf5mushu**
1918
- **Documentation - [Wiki](https://github.com/Ankit404butfound/PyWhatKit/wiki)**
2019

2120
## Installation and Supported Versions
@@ -37,6 +36,18 @@ PyWhatKit officially supports Python 3.8+.
3736
```bash
3837
git clone https://github.com/Ankit404butfound/PyWhatKit.git
3938
```
39+
## What's new in v5.3?
40+
```py
41+
import pywahtkit
42+
pywhatkit.start_server()
43+
```
44+
### This method can be used to remotely control your PC using your phone (Windows only)
45+
- Make sure your PC and your phone are on same network, on your PC, Open Network and Internet Settings > Properties > Network Profile, make sure it's set to Private.
46+
- Run the above code and then open command prompt and type `ipconfig`.
47+
- Search for `IPv4 Address` and on your phone's browser type this address and append `:8000` at the end, example `192.168.0.1:8000`.
48+
- Try moving you finger and you should notice your cursor moving too.
49+
- You can also type and scroll too, enjoy.
50+
- More information here https://pywhatkit.herokuapp.com/remote-kit with the raw code.
4051

4152
## Features
4253

pywhatkit/remotekit.py

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
import logging
2+
import sys
3+
import threading
4+
5+
import pyautogui as p
6+
from flask import Flask, request
7+
8+
log = logging.getLogger("werkzeug")
9+
log.setLevel(logging.ERROR)
10+
11+
cli = sys.modules["flask.cli"]
12+
cli.show_server_banner = lambda *x: None
13+
14+
app = Flask("app")
15+
16+
p.FAILSAFE = False
17+
moving = False
18+
drag = False
19+
type_data = ""
20+
old_data = ""
21+
coords = (0, 0)
22+
lastcords = (0, 0)
23+
lstmcord = (0, 0)
24+
lstlen = 0
25+
coords = [(0, 0)]
26+
27+
28+
@app.route("/", methods=["GET", "POST"])
29+
def send() -> str:
30+
# print("here")
31+
if request.method == "POST":
32+
# print(request.get_json())
33+
return "ok"
34+
return """<!DOCTYPE html>
35+
<html>
36+
<head>
37+
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
38+
<meta name='viewport'
39+
content='width=device-width, initial-scale=1.0, maximum-scale=1.0,
40+
user-scalable=0' >
41+
<script type="text/javascript" charset="utf-8">
42+
function init() {
43+
var touchzone = document.getElementById("zone");
44+
touchzone.addEventListener("touchend", clicke, false);
45+
touchzone.addEventListener("touchmove", handle, false);
46+
touchzone.addEventListener("touchstart", tostart, false);
47+
var scrollzone = document.getElementById("scroll");
48+
scrollzone.addEventListener("touchmove", scrollmove, false);
49+
scrollzone.addEventListener("touchstart", tostart, false);
50+
}
51+
52+
function scrollmove(event){
53+
var a = event.touches[0].pageX;
54+
var b = event.touches[0].pageY;
55+
var xhttp = new XMLHttpRequest();
56+
xhttp.onreadystatechange = function() {
57+
};
58+
xhttp.open("POST", "scroller", true);
59+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
60+
xhttp.send("a="+a+"&b="+b);
61+
}
62+
63+
64+
function tostart(event){
65+
var a = event.touches[0].pageX;
66+
var b = event.touches[0].pageY;
67+
var xhttp = new XMLHttpRequest();
68+
xhttp.onreadystatechange = function() {
69+
};
70+
xhttp.open("POST", "tstart", true);
71+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
72+
xhttp.send("a="+a+"&b="+b);
73+
}
74+
75+
function clicke(event) {
76+
var xhttp = new XMLHttpRequest();
77+
xhttp.onreadystatechange = function() {
78+
};
79+
var a = event.changedTouches[0].pageY;
80+
xhttp.open("POST", "click", true);
81+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
82+
xhttp.send("a="+a);
83+
}
84+
85+
function dragm() {
86+
var btn = document.getElementById("drag");
87+
var xhttp = new XMLHttpRequest();
88+
xhttp.onreadystatechange = function() {
89+
};
90+
xhttp.open("POST", "dradhandler", true);
91+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
92+
xhttp.send();
93+
94+
if (btn.innerHTML == "Drag mouse"){
95+
btn.innerHTML = "Move mouse";
96+
}
97+
else{
98+
btn.innerHTML = "Drag mouse";
99+
}
100+
}
101+
102+
function sendData(a,b,g) {
103+
var xhttp = new XMLHttpRequest();
104+
xhttp.onreadystatechange = function() {
105+
};
106+
xhttp.open("POST", "handler", true);
107+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
108+
xhttp.send("a="+a+"&b="+b);
109+
}
110+
111+
112+
function handle(event) {
113+
var alpha = event.touches[0].pageX;
114+
var beta = event.touches[0].pageY;
115+
sendData(alpha,beta);
116+
}
117+
118+
119+
function on_input(){
120+
var data = document.getElementById("inpfield").value;
121+
var xhttp = new XMLHttpRequest();
122+
xhttp.onreadystatechange = function() {
123+
};
124+
xhttp.open("POST", "typed", true);
125+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
126+
xhttp.send("data="+data);
127+
}
128+
function enter_but(){
129+
var xhttp = new XMLHttpRequest();
130+
xhttp.onreadystatechange = function() {
131+
};
132+
xhttp.open("POST", "enter", true);
133+
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
134+
xhttp.send("data="+"data");
135+
}
136+
137+
138+
139+
140+
</script>
141+
142+
<meta name="" content="">
143+
<title></title>
144+
<style>
145+
.center{
146+
position: fixed;
147+
background-color: rgb(230,230,230);
148+
width:80%;
149+
height:400px;
150+
top:300px;
151+
left:46%;
152+
color:rgb(200,200,200);
153+
font-weight:bold;
154+
transform: translate(-50%,-50%);
155+
-webkit-touch-callout: none;
156+
-webkit-user-select: none;
157+
-khtml-user-select: none;
158+
-moz-user-select: none;
159+
-ms-user-select: none;
160+
user-select: none;
161+
}
162+
html{
163+
touch-action:pan-down
164+
}
165+
166+
.scrollarea{
167+
position: fixed;
168+
background-color: rgb(230,230,230);
169+
width:30px;
170+
height:400px;
171+
top:300px;
172+
left:92.05%;
173+
color:rgb(200,200,200);
174+
font-weight:bold;
175+
transform: translate(-50%,-50%);
176+
-webkit-touch-callout: none;
177+
-webkit-user-select: none;
178+
-khtml-user-select: none;
179+
-moz-user-select: none;
180+
-ms-user-select: none;
181+
user-select: none;
182+
text-align:center;
183+
}
184+
185+
186+
</style>
187+
</head>
188+
<body onload="init()">
189+
<p style="text-align:center;">Type on PC
190+
<input id="inpfield"type="text" oninput=on_input()></input>
191+
<button type="button" onclick="enter_but()">Enter</button></p>
192+
<div style="text-align:center;">
193+
<button id="drag" type="button" onclick="dragm()">Drag mouse</button>
194+
</div>
195+
<div class="center" id="zone">
196+
<p align="center"><br><br><br><br><br><br>Left click area<br><br><br><br><br><br><hr></p>
197+
<p align="center"><br>Right click area</p>
198+
</div>
199+
<div class="scrollarea" id="scroll">
200+
<p><br><br><br><br><br>S<br>C<br>R<br>O<br>L<br>L</p>
201+
</div>
202+
</body>
203+
</html>"""
204+
205+
206+
@app.route("/handler", methods=["POST"])
207+
def handle() -> str:
208+
global moving, cordlst, lastcords
209+
lst = []
210+
a = request.form["a"]
211+
b = request.form["b"]
212+
a = float(a)
213+
b = float(b)
214+
moving = True
215+
coords = (a, b)
216+
lx, ly = lastcords
217+
cx, cy = coords
218+
# print(cx,cy)
219+
# p.moveRel((cx-lx)/2,(cy-ly)/2)
220+
threading.Thread(target=lambda: p.moveRel((cx - lx) * 2, (cy - ly) * 2)).start()
221+
lastcords = coords
222+
return "1"
223+
224+
225+
@app.route("/scroller", methods=["POST"])
226+
def scrollerr() -> str:
227+
global moving, cordlst, lastcords2
228+
a = request.form["a"]
229+
b = request.form["b"]
230+
a = float(a)
231+
b = float(b)
232+
coords = (a, b)
233+
lx, ly = lastcords2
234+
cx, cy = coords
235+
if cy < ly:
236+
threading.Thread(target=lambda: p.scroll(50)).start()
237+
if cy > ly:
238+
threading.Thread(target=lambda: p.scroll(-50)).start()
239+
lastcords2 = coords
240+
return "1"
241+
242+
243+
@app.route("/tstart", methods=["POST"])
244+
def startt() -> str:
245+
global lastcords, lastcords2
246+
# print("end")
247+
a = request.form["a"]
248+
b = request.form["b"]
249+
# print(a,b)
250+
a = float(a)
251+
b = float(b)
252+
lastcords = (a, b)
253+
lastcords2 = (a, b)
254+
return "1"
255+
256+
257+
@app.route("/click", methods=["POST"])
258+
def do_click() -> str:
259+
global moving
260+
if not moving:
261+
a = request.form["a"]
262+
# print(a)
263+
a = float(a)
264+
if a < 400:
265+
p.click()
266+
if a >= 400:
267+
p.rightClick()
268+
269+
moving = False
270+
return "1"
271+
272+
273+
@app.route("/typed", methods=["POST"])
274+
def typeit() -> str:
275+
global type_data, old_data
276+
data = request.form["data"]
277+
type_data = str(data)
278+
if len(type_data) > len(old_data):
279+
p.typewrite(type_data[len(type_data) - 1])
280+
else:
281+
p.press("backspace", len(old_data) - len(type_data))
282+
old_data = type_data
283+
return "1"
284+
285+
286+
@app.route("/enter", methods=["POST"])
287+
def slashN() -> str:
288+
p.press("enter")
289+
return "1"
290+
291+
292+
@app.route("/dradhandler", methods=["POST"])
293+
def ghasit_mouse() -> str:
294+
global drag
295+
# print(drag)
296+
if drag == True:
297+
drag = False
298+
p.mouseUp()
299+
300+
else:
301+
drag = True
302+
p.mouseDown()
303+
304+
return "1"
305+
306+
307+
def start_server(port=8000, print_msg=True):
308+
if print_msg:
309+
print("Server started at local_ip_of_this_pc:%s" % port)
310+
print("Print Ctrl+C to exit")
311+
app.run(host="0.0.0.0", port=port)
312+
313+
314+
# app.run(host='0.0.0.0')
315+
#
316+
#
317+
# def main():
318+
# app.run(host="192.168.43.17", port=33)
319+
#
320+
#
321+
# if __name__ == "__main__":
322+
# main()
323+
# app.run(host='localhost')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def readme() -> str:
1212
setup(
1313
name="pywhatkit",
1414
packages=setuptools.find_packages(),
15-
version="5.2",
15+
version="5.3",
1616
license="MIT",
1717
description="PyWhatKit is a Simple and Powerful WhatsApp Automation Library with many useful Features",
1818
author="Ankit Raj Mahapatra",

0 commit comments

Comments
 (0)