├── .gitignore ├── README.md ├── cat ├── KeyTapHand1.png ├── KeyTapHand2.png ├── cat.ico ├── mouse │ ├── green │ │ ├── Hand A.png │ │ ├── Hand B.png │ │ ├── Hand C.png │ │ ├── Hand D.png │ │ ├── Hand E.png │ │ ├── Hand F.png │ │ ├── Hand G.png │ │ ├── Hand H.png │ │ ├── Hand I.png │ │ ├── Hand IA.png │ │ ├── Hand IB.png │ │ ├── Hand IC.png │ │ └── Hand ID.png │ └── standard │ │ ├── Hand A.png │ │ ├── Hand B.png │ │ ├── Hand C.png │ │ ├── Hand D.png │ │ ├── Hand E.png │ │ ├── Hand F.png │ │ ├── Hand G.png │ │ ├── Hand H.png │ │ ├── Hand I.png │ │ ├── Hand IA.png │ │ ├── Hand IB.png │ │ ├── Hand IC.png │ │ └── Hand ID.png └── tablet │ ├── green │ ├── Hand A.png │ ├── Hand B.png │ ├── Hand C.png │ ├── Hand D.png │ ├── Hand E.png │ ├── Hand F.png │ ├── Hand G.png │ ├── Hand H.png │ ├── Hand I.png │ ├── Hand IA.png │ ├── Hand IB.png │ ├── Hand IC.png │ └── Hand ID.png │ └── standard │ ├── Hand A.png │ ├── Hand B.png │ ├── Hand C.png │ ├── Hand D.png │ ├── Hand E.png │ ├── Hand F.png │ ├── Hand G.png │ ├── Hand H.png │ ├── Hand I.png │ ├── Hand IA.png │ ├── Hand IB.png │ ├── Hand IC.png │ └── Hand ID.png └── osu!cat.py /.gitignore: -------------------------------------------------------------------------------- 1 | img.psd -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## osu!cat 2 | This is a python application that tracks the cursor position and key inputs to create a Bongo Cat window which can be used as an overlay for streaming/recording applications. 3 | ## [Latest version](https://github.com/ZeCryptic/osu-cat/releases/tag/v1.2.0) 4 | * Window is now resizable (thanks JapanPanda) 5 | * Dragging the window should no longer be buggy 6 | * Added an option for chroma key green background 7 | * More performance fixes (thanks JapanPanda) 8 | 9 | ## How to use 10 | 1. Download the [latest version](https://github.com/ZeCryptic/osu-cat/releases/tag/v1.2.0) of osu!cat. 11 | 2. Extract the .rar file using a file archiver such as 7-Zip. 12 | 3. Run the .exe inside the extracted folder. 13 | 4. Wait a few seconds until two windows appear and press the first and second key that you want Bongo Cat to react on in the first window. 14 | 5. Press either 0 for Bongo Cat to use a tablet or 1 for Bongo Cat to use a mouse. 15 | 6. Press 1 to use a chroma key green background or 0 if you don't want it. You should see Bongo Cat in the other window 16 | 17 | ## Changing the cat images 18 | It is entirely possible to edit the png files to make the cat look different (totally understandable, they look bad). However, when doing so you need to make sure that the new picture files have a color depth of 32 bits. Otherwise the program will not work. One way of doing this is by just re-saving the images in a program like paint.net and select the [32-bit color depth option](http://puu.sh/ByjvT/8023ae8252.png). I plan on fixing this bug in the future 19 | -------------------------------------------------------------------------------- /cat/KeyTapHand1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/KeyTapHand1.png -------------------------------------------------------------------------------- /cat/KeyTapHand2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/KeyTapHand2.png -------------------------------------------------------------------------------- /cat/cat.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/cat.ico -------------------------------------------------------------------------------- /cat/mouse/green/Hand A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand A.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand B.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand C.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand D.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand E.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand F.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand F.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand G.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand G.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand H.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand I.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand I.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand IA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand IA.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand IB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand IB.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand IC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand IC.png -------------------------------------------------------------------------------- /cat/mouse/green/Hand ID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/green/Hand ID.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand A.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand B.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand C.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand D.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand E.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand F.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand F.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand G.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand G.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand H.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand I.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand I.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand IA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand IA.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand IB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand IB.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand IC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand IC.png -------------------------------------------------------------------------------- /cat/mouse/standard/Hand ID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/mouse/standard/Hand ID.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand A.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand B.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand C.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand D.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand E.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand F.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand F.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand G.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand G.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand H.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand I.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand I.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand IA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand IA.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand IB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand IB.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand IC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand IC.png -------------------------------------------------------------------------------- /cat/tablet/green/Hand ID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/green/Hand ID.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand A.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand B.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand C.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand D.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand E.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand F.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand F.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand G.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand G.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand H.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand I.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand I.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand IA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand IA.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand IB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand IB.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand IC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand IC.png -------------------------------------------------------------------------------- /cat/tablet/standard/Hand ID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeCryptic/osu-cat/ffee12a614e22e2dfa0375a1bb7af5e453b68c50/cat/tablet/standard/Hand ID.png -------------------------------------------------------------------------------- /osu!cat.py: -------------------------------------------------------------------------------- 1 | from tkinter import Tk, Label 2 | import PIL.ImageTk 3 | import PIL.Image 4 | from keyboard import is_pressed 5 | from win32gui import GetCursorPos 6 | from math import sqrt 7 | from time import sleep 8 | from sys import exit 9 | 10 | version = 'v1.2.0' 11 | 12 | start = False 13 | drag = False 14 | drag_id = '' 15 | 16 | def close_window(): 17 | root.withdraw() 18 | exit() # Ensures python window exits 19 | 20 | def resize(): 21 | window_x = root.winfo_width() 22 | window_y = root.winfo_height() 23 | if window_x > window_y: 24 | root.geometry('{0}x{0}'.format(window_x)) 25 | elif window_y > window_x: 26 | root.geometry('{0}x{0}'.format(window_y)) 27 | 28 | def dragging(event): 29 | global drag_id 30 | global drag 31 | if drag_id == '': 32 | pass 33 | else: 34 | root.after_cancel(drag_id) 35 | drag = True 36 | drag_id = root.after(100, stop_drag) 37 | 38 | def stop_drag(): 39 | global drag_id 40 | global drag 41 | drag = False 42 | drag_id = '' 43 | 44 | root = Tk() 45 | root.resizable(width=True, height=True) 46 | root.geometry('640x640') 47 | root.maxsize(width=640, height=640) # Max size is the original image size 48 | root.minsize(width=124, height=124) 49 | root.title('osu!cat ' + version) 50 | root.protocol('WM_DELETE_WINDOW', close_window) 51 | 52 | screen_x = root.winfo_screenwidth() 53 | screen_y = root.winfo_screenheight() 54 | add = (screen_x - screen_y)/2 55 | 56 | x_1 = add + screen_y/6 57 | x_2 = x_1 + screen_y/3 58 | x_3 = x_2 + screen_y/3 59 | y_1 = screen_y/6 60 | y_2 = y_1 + screen_y/3 61 | y_3 = y_2 + screen_y/3 62 | ix_1 = screen_y/3 + add 63 | ix_2 = ix_1 + screen_y/3 64 | iy_1 = screen_y/3 65 | iy_2 = iy_1 + screen_y/3 66 | 67 | d_bias = screen_x/8 68 | 69 | 70 | frame_points = {'A': (x_1, y_1), 71 | 'B': (x_2, y_1), 72 | 'C': (x_3, y_1), 73 | 'D': (x_1, y_2), 74 | 'E': (x_2, y_2), 75 | 'F': (x_3, y_2), 76 | 'G': (x_1, y_3), 77 | 'H': (x_2, y_3), 78 | 'I': (x_3, y_3), 79 | 'IA': (ix_1, iy_1), 80 | 'IB': (ix_2, iy_1), 81 | 'IC': (ix_1, iy_2), 82 | 'ID': (ix_2, iy_2)} 83 | 84 | def find_distance(cx, cy, px, py): # Calculates the distance from the cursor position to a point 85 | d = sqrt((px-cx)**2 + (py-cy)**2) # Euclidean metric 86 | return d 87 | 88 | def find_frame(cx, cy, f): 89 | 90 | best_d = [10000, 'NaN'] 91 | for key, value in frame_points.items(): 92 | 93 | d = find_distance(cx, cy, value[0], value[1]) 94 | 95 | if key == f: 96 | d -= d_bias 97 | 98 | if d < best_d[0]: 99 | best_d[0] = d 100 | best_d[1] = key 101 | 102 | return best_d[1] 103 | 104 | print('Bongo Cat Live Cam ' + version) 105 | print('----------------------------------------------------------------------------------------------------------------------') 106 | print('Disclaimer: There is a high probability you will experience some bugs or that the program will now work at all.\n' 107 | 'This program will also most likely not work on resolutions where the height is bigger than the width and there\n' 108 | 'is no support for custom ingame resolutions or sensitivities. You have been warned.') 109 | print('----------------------------------------------------------------------------------------------------------------------') 110 | print('Before you can use this program you need to configure some things') 111 | while True: 112 | k1 = input('Key 1: ') 113 | k2 = input('Key 2: ') 114 | if len(k1) == 1 and len(k2) == 1: 115 | break 116 | else: 117 | print('Keys can only be 1 character long') 118 | 119 | print('(Type 0 for tablet and 1 for mouse)') 120 | while True: 121 | i_type = input('Tablet or mouse: ') 122 | if i_type == '0': 123 | cursor_device = 'tablet' 124 | break 125 | elif i_type == '1': 126 | cursor_device = 'mouse' 127 | break 128 | else: 129 | print('Invalid input') 130 | 131 | print('(Type 0 for no and 1 for yes)') 132 | while True: 133 | i_type = input('Use chroma key green background?: ') 134 | if i_type == '0': 135 | background = 'standard' 136 | start = True 137 | break 138 | elif i_type == '1': 139 | background = 'green' 140 | start = True 141 | break 142 | else: 143 | print('Invalid input') 144 | 145 | print('All done! To reconfigure, just close and relaunch the application') 146 | print('Note: When re-sizing, hit k1 or k2 to reload the image!') 147 | 148 | 149 | #preload all images 150 | hit_images = { 151 | 1: PIL.Image.open("cat/KeyTapHand1.png"), 152 | 2: PIL.Image.open("cat/KeyTapHand2.png") 153 | } 154 | 155 | cursor_images = {} 156 | for key in frame_points.keys(): 157 | cursor_images[key] = PIL.Image.open("cat/{0}/{1}/Hand {2}.png".format(cursor_device, background, key)) 158 | 159 | default_img = PIL.ImageTk.PhotoImage(cursor_images['A']) 160 | image_label = Label(root, image=default_img) 161 | image_label.image = default_img 162 | image_label.pack() 163 | 164 | f = 'A' 165 | f_prev = f 166 | w_size = root.winfo_width, root.winfo_height 167 | w_size_prev = w_size 168 | k1_p_prev = False 169 | k2_p_prev = False 170 | first_iteration = True 171 | force_update = True 172 | last_hit = 1 173 | 174 | def iterate(): 175 | global f, f_prev, k1_p_prev, k2_p_prev, last_hit, drag, w_size_prev, w_size, first_iteration, force_update 176 | if drag: 177 | root.after(5, iterate) 178 | return 179 | 180 | k1_p = is_pressed(k1) 181 | k2_p = is_pressed(k2) 182 | x, y = GetCursorPos() 183 | f = find_frame(x, y, f) 184 | 185 | base_img = cursor_images[f] 186 | 187 | def forceUpdate(): 188 | base_img = cursor_images[f].resize((root.winfo_width(), root.winfo_height()), PIL.Image.ANTIALIAS) 189 | n_base_img = PIL.ImageTk.PhotoImage(base_img) 190 | image_label.configure(image=n_base_img) 191 | image_label.image = n_base_img 192 | root.update() 193 | 194 | if first_iteration: 195 | first_iteration = False 196 | forceUpdate() 197 | root.after(0, iterate) 198 | return 199 | 200 | resize() 201 | 202 | if f == f_prev and k1_p == k1_p_prev and k2_p == k2_p_prev: 203 | root.after(5, iterate) 204 | return 205 | 206 | if k1_p or k2_p: 207 | force_update = True 208 | if (k1_p and not k1_p_prev) or (not k2_p and k2_p_prev): 209 | final_hit = 1 210 | elif (k2_p and not k2_p_prev) or (not k1_p and k1_p_prev): 211 | final_hit = 2 212 | else: 213 | final_hit = last_hit 214 | 215 | last_hit = final_hit 216 | final_hit_img = hit_images[final_hit] 217 | composite_image = PIL.Image.alpha_composite(base_img, final_hit_img) 218 | composite_image.thumbnail((root.winfo_width(), root.winfo_height()), PIL.Image.ANTIALIAS) 219 | n_base_img = PIL.ImageTk.PhotoImage(composite_image) 220 | else: 221 | base_img = base_img.resize((root.winfo_width(), root.winfo_height()), PIL.Image.ANTIALIAS) 222 | n_base_img = PIL.ImageTk.PhotoImage(base_img) 223 | 224 | f_prev = f 225 | k1_p_prev = k1_p 226 | k2_p_prev = k2_p 227 | 228 | image_label.configure(image=n_base_img) 229 | image_label.image = n_base_img 230 | root.update() 231 | root.after(5, iterate) 232 | 233 | if start: 234 | root.bind('', dragging) 235 | root.after(0, iterate) 236 | root.mainloop() 237 | --------------------------------------------------------------------------------