forked from bnl1/fnf-auto-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfnf-auto-script.py
More file actions
75 lines (57 loc) · 2.13 KB
/
fnf-auto-script.py
File metadata and controls
75 lines (57 loc) · 2.13 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
71
72
73
74
75
import numpy as np
import cv2
from mss import mss
from PIL import Image
from pynput.keyboard import Key, Controller, Listener
from time import sleep
# Position of the scanned window
bounding_box = {'top': 128, 'left': 1000, 'width': 596, 'height': 185}
# The number here is the height in which the script detects arrows
row = 210 - bounding_box['top']
# Global coordinates for x
arrows = {'left': 1075, 'down': 1227, 'up': 1372, 'right': 1527}
# Calculating local coordinations
for key in arrows:
arrows[key] -= bounding_box['left']
# Default grey RGB (as [G, B, R])
grey = [173, 163, 135]
# Default grey in senpai level
grey_senpai = [200, 186, 162]
# Inicialization of screen grabber and virtual keyboard
sct = mss()
keyboard = Controller()
# Arrow keys
keys = {'left': Key.left, 'down': Key.down, 'up': Key.up, 'right': Key.right}
input("Ready?")
# Waits for the grey arrows to appear
while True:
sct_img = sct.grab(bounding_box)
arr = np.array(sct_img)
if(list(arr[row][arrows['right']][:3]) == grey or list(arr[row][arrows['right']][:3]) == grey_senpai):
break
# Main loop
while True:
while True:
# Grabs image
sct_img = sct.grab(bounding_box)
# Converts the image into numpy array
arr = np.array(sct_img)
# Shows it on screen (mainly for debugging)
cv2.imshow('screen', arr)
# Goes trough all positions to test if key should be pressed
for key in arrows:
# Tests for not grey
if(list(arr[row][arrows[key]][:3]) != grey and list(arr[row][arrows[key]][:3]) != grey_senpai):
keyboard.press(keys[key])
print(key)
sleep(0.04)
break
# Releases all keys
for k in arrows:
keyboard.release(keys[k])
# Pressing q when focused on the 'camera' screen will end the loop (sometimes)
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
# For repeat
input("Wanna continue?")