-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetooth_kb.py
48 lines (31 loc) · 1.23 KB
/
bluetooth_kb.py
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
#______ ___ __ _______ _____
#| ___ \ / _ \ \ \ / /_ _|_ _|
#| |_/ /__ _ __ _ __ / /_\ \_ __ _ __ ___ \ V / | | | |
#| __/ _ \ '_ \| '_ \| _ | '_ \| '_ \/ __| / \ | | | |
#| | | __/ | | | | | | | | | |_) | |_) \__ \ / /^\ \_| |_ _| |_
#\_| \___|_| |_|_| |_\_| |_/ .__/| .__/|___/ \/ \/\___/ \___/
# | | | |
# |_| |_|
# Bluetooth to keyboard event
import bluetooth, sys
TARGET_NAME = "Galaxy S5 CM"
target_address = None
print("Recommended: pair the phone with Bluetooth.")
print("Searching for nearby devices...")
nearby_devices = bluetooth.discover_devices(duration=10)
for bdaddr in nearby_devices:
lookup = bluetooth.lookup_name(bdaddr)
print(bdaddr, lookup)
if TARGET_NAME == lookup:
target_address = bdaddr
break
if target_address:
print("Found target", TARGET_NAME)
else:
print("Could not find bluetooth device nearby.")
sys.exit()
server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
PORT = 1337
server_sock.bind(("", PORT))
server_sock.listen(1)
print(server_sock.getsockname())