D
D
Dronicon2021-05-14 11:20:48
Python
Dronicon, 2021-05-14 11:20:48

How to forcefully end reading a macro in a variable?

I can't figure out how to forcibly stop reading the variable in which the macro is located. My task is to make it so that when a button is pressed, it plays, and when another button is pressed, it stops playing it. (or do this while I hold the button - it plays, I release it - it stops without reaching the end). And all this needs to be looped so that each time it reads the variable from scratch, when it is pressed again.

import mouse
import keyboard
from mouse import MoveEvent
 
macro = [MoveEvent(x=699, y=894, time=1620919775.0998528), MoveEvent(x=711, y=887, time=1620919775.0998528), MoveEvent(x=722, y=877, time=1620919775.1078522), MoveEvent(x=728, y=871, time=1620919775.1158533), MoveEvent(x=730, y=863, time=1620919775.1238537), MoveEvent(x=729, y=849, time=1620919775.131854), MoveEvent(x=723, y=830, time=1620919775.139857), MoveEvent(x=702, y=793, time=1620919775.1478567), MoveEvent(x=689, y=767, time=1620919775.1478567), MoveEvent(x=665, y=733, time=1620919775.1558573), MoveEvent(x=635, y=686, time=1620919775.1638796), MoveEvent(x=608, y=645, time=1620919775.1718767), MoveEvent(x=587, y=611, time=1620919775.1798766), MoveEvent(x=570, y=579, time=1620919775.1878612), MoveEvent(x=557, y=550, time=1620919775.1958797), MoveEvent(x=548, y=528, time=1620919775.2038808), MoveEvent(x=541, y=510, time=1620919775.2038808), MoveEvent(x=537, y=502, time=1620919775.2118802), MoveEvent(x=534, y=498, time=1620919775.220165), MoveEvent(x=532, y=496, time=1620919775.2281752), MoveEvent(x=531, y=495, time=1620919775.2361748), MoveEvent(x=530, y=495, time=1620919775.2441769), MoveEvent(x=528, y=495, time=1620919775.2521772), MoveEvent(x=524, y=495, time=1620919775.2521772), MoveEvent(x=518, y=497, time=1620919775.2601829), MoveEvent(x=513, y=500, time=1620919775.268179), MoveEvent(x=502, y=508, time=1620919775.276197), MoveEvent(x=484, y=535, time=1620919775.2841806), MoveEvent(x=473, y=560, time=1620919775.2921972), MoveEvent(x=464, y=591, time=1620919775.300198), MoveEvent(x=462, y=626, time=1620919775.3081994), MoveEvent(x=465, y=661, time=1620919775.3081994), MoveEvent(x=481, y=712, time=1620919775.3161838), MoveEvent(x=500, y=749, time=1620919775.3241866), MoveEvent(x=528, y=792, time=1620919775.332188), MoveEvent(x=564, y=840, time=1620919775.3401864), MoveEvent(x=593, y=870, time=1620919775.3482034), MoveEvent(x=623, y=888, time=1620919775.3562045), MoveEvent(x=655, y=900, time=1620919775.3722064), MoveEvent(x=685, y=907, time=1620919775.3722064), MoveEvent(x=719, y=907, time=1620919775.3722064), MoveEvent(x=745, y=905, time=1620919775.3806484), MoveEvent(x=775, y=897, time=1620919775.3886576), MoveEvent(x=817, y=882, time=1620919775.396675), MoveEvent(x=847, y=864, time=1620919775.4046764), MoveEvent(x=874, y=844, time=1620919775.4130402), MoveEvent(x=906, y=819, time=1620919775.4130402), MoveEvent(x=935, y=789, time=1620919775.4210653), MoveEvent(x=962, y=760, time=1620919775.429065), MoveEvent(x=983, y=727, time=1620919775.4370565), MoveEvent(x=1004, y=675, time=1620919775.4466794), MoveEvent(x=1018, y=631, time=1620919775.454689), MoveEvent(x=1026, y=594, time=1620919775.454689), MoveEvent(x=1026, y=553, time=1620919775.462691), MoveEvent(x=1025, y=540, time=1620919775.4706907), MoveEvent(x=1021, y=529, time=1620919775.478693), MoveEvent(x=1016, y=515, time=1620919775.4867136), MoveEvent(x=1008, y=503, time=1620919775.4956315), MoveEvent(x=998, y=492, time=1620919775.5036387), MoveEvent(x=987, y=483, time=1620919775.5036387), MoveEvent(x=978, y=477, time=1620919775.5116394), MoveEvent(x=959, y=475, time=1620919775.5196407), MoveEvent(x=946, y=475, time=1620919775.5300825), MoveEvent(x=933, y=475, time=1620919775.5381572), MoveEvent(x=919, y=476, time=1620919775.5381572), MoveEvent(x=907, y=479, time=1620919775.5460916), MoveEvent(x=897, y=483, time=1620919775.5540917), MoveEvent(x=885, y=488, time=1620919775.562109), MoveEvent(x=874, y=496, time=1620919775.5701149), MoveEvent(x=861, y=503, time=1620919775.5781164), MoveEvent(x=854, y=508, time=1620919775.5863254), MoveEvent(x=848, y=513, time=1620919775.5863254), MoveEvent(x=843, y=521, time=1620919775.5943503), MoveEvent(x=841, y=528, time=1620919775.6023347), MoveEvent(x=839, y=540, time=1620919775.6103523), MoveEvent(x=841, y=558, time=1620919775.6204503), MoveEvent(x=852, y=584, time=1620919775.628459), MoveEvent(x=872, y=623, time=1620919775.628459), MoveEvent(x=886, y=646, time=1620919775.6364756), MoveEvent(x=907, y=680, time=1620919775.6444597), MoveEvent(x=930, y=711, time=1620919775.6524773), MoveEvent(x=947, y=735, time=1620919775.6604788), MoveEvent(x=959, y=748, time=1620919775.6684797), MoveEvent(x=972, y=759, time=1620919775.6764812), MoveEvent(x=984, y=767, time=1620919775.6764812), MoveEvent(x=998, y=776, time=1620919775.684463), MoveEvent(x=1007, y=779, time=1620919775.6927807), MoveEvent(x=1014, y=783, time=1620919775.7008061), MoveEvent(x=1026, y=783, time=1620919775.7088077), MoveEvent(x=1034, y=783, time=1620919775.7168078), MoveEvent(x=1045, y=782, time=1620919775.7257445), MoveEvent(x=1059, y=773, time=1620919775.7257445), MoveEvent(x=1073, y=765, time=1620919775.73377), MoveEvent(x=1092, y=749, time=1620919775.74177), MoveEvent(x=1103, y=736, time=1620919775.7497718), MoveEvent(x=1116, y=719, time=1620919775.7595344), MoveEvent(x=1134, y=689, time=1620919775.7675443), MoveEvent(x=1147, y=663, time=1620919775.7675443), MoveEvent(x=1161, y=631, time=1620919775.7755487), MoveEvent(x=1171, y=594, time=1620919775.7835462), MoveEvent(x=1176, y=568, time=1620919775.7915635), MoveEvent(x=1178, y=543, time=1620919775.7995687), MoveEvent(x=1178, y=525, time=1620919775.8075695), MoveEvent(x=1176, y=503, time=1620919775.8157234), MoveEvent(x=1171, y=477, time=1620919775.8157234), MoveEvent(x=1165, y=462, time=1620919775.823734), MoveEvent(x=1158, y=444, time=1620919775.8317494), MoveEvent(x=1148, y=430, time=1620919775.839751), MoveEvent(x=1141, y=421, time=1620919775.8500724), MoveEvent(x=1135, y=415, time=1620919775.8580813), MoveEvent(x=1129, y=410, time=1620919775.8580813), MoveEvent(x=1121, y=403, time=1620919775.8660915), MoveEvent(x=1111, y=399, time=1620919775.8740823), MoveEvent(x=1103, y=399, time=1620919775.8820837), MoveEvent(x=1089, y=398, time=1620919775.890102), MoveEvent(x=1077, y=401, time=1620919775.8981032), MoveEvent(x=1066, y=406, time=1620919775.9060864), MoveEvent(x=1057, y=413, time=1620919775.9060864), MoveEvent(x=1049, y=424, time=1620919775.914102), MoveEvent(x=1039, y=438, time=1620919775.9220872), MoveEvent(x=1034, y=452, time=1620919775.9300873), MoveEvent(x=1025, y=479, time=1620919775.940241), MoveEvent(x=1019, y=500, time=1620919775.9471114), MoveEvent(x=1016, y=516, time=1620919775.9551191), MoveEvent(x=1015, y=531, time=1620919775.9551191), MoveEvent(x=1015, y=546, time=1620919775.9631193), MoveEvent(x=1018, y=560, time=1620919775.971137), MoveEvent(x=1022, y=574, time=1620919775.979133), MoveEvent(x=1026, y=581, time=1620919775.9871407), MoveEvent(x=1031, y=589, time=1620919775.9951396), MoveEvent(x=1038, y=596, time=1620919776.0031428), MoveEvent(x=1046, y=601, time=1620919776.0031428), MoveEvent(x=1053, y=606, time=1620919776.0181658), MoveEvent(x=1065, y=610, time=1620919776.0181658), MoveEvent(x=1079, y=613, time=1620919776.0261881), MoveEvent(x=1091, y=614, time=1620919776.0341885), MoveEvent(x=1107, y=614, time=1620919776.042191), MoveEvent(x=1121, y=614, time=1620919776.0501914), MoveEvent(x=1130, y=610, time=1620919776.0583878), MoveEvent(x=1135, y=608, time=1620919776.0664136), MoveEvent(x=1143, y=600, time=1620919776.0664136), MoveEvent(x=1147, y=591, time=1620919776.0743973), MoveEvent(x=1150, y=576, time=1620919776.082415), MoveEvent(x=1148, y=557, time=1620919776.0930705), MoveEvent(x=1140, y=527, time=1620919776.101078), MoveEvent(x=1136, y=512, time=1620919776.101078), MoveEvent(x=1129, y=496, time=1620919776.1090796), MoveEvent(x=1120, y=480, time=1620919776.1170802), MoveEvent(x=1117, y=475, time=1620919776.1250982), MoveEvent(x=1115, y=472, time=1620919776.1344535), MoveEvent(x=1112, y=470, time=1620919776.1424778), MoveEvent(x=1112, y=470, time=1620919776.1424778), MoveEvent(x=1111, y=470, time=1620919776.1504786), MoveEvent(x=1109, y=470, time=1620919776.1584606), MoveEvent(x=1108, y=471, time=1620919776.166464), MoveEvent(x=1105, y=474, time=1620919776.1744812), MoveEvent(x=1101, y=480, time=1620919776.182482), MoveEvent(x=1096, y=486, time=1620919776.1912766), MoveEvent(x=1091, y=498, time=1620919776.1912766), MoveEvent(x=1090, y=507, time=1620919776.1993017), MoveEvent(x=1088, y=522, time=1620919776.2073019), MoveEvent(x=1090, y=535, time=1620919776.2153037)]
# mouse.hook(macro.append)
# keyboard.wait("l")
# mouse.unhook(macro.append)
print('Можно включить макрос\n')
keyboard.wait("c")
mouse.play(macro)
print(macro)


Now it works, if I press 'c', the macro stored in the variable will start to be read (played) to its end.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question