I'm glad it works now. I added the new functions anyway so that it should be more versatile:
will press a key when the mouse button is released (it requires extra flags).
Code: Select all
def radial_buttons_hold(overlap, key1, key2, key3, key4):
global x
global y
global theta
global mb_active
offset = 90
min_swipe = 10
x += mouse.deltaX
y += mouse.deltaY
if (x*x + y*y) > min_swipe*min_swipe:
mb_active = True
if x > 0:
theta = math.atan(y/x) * 180 / math.pi + offset
elif x < 0:
theta = ( math.atan(y/x) + math.pi ) * 180 / math.pi + offset
else:
if y > 0:
theta = 90 + offset
elif y < 0:
theta = -90 + offset
else:
theta = -91 + offset
ol = overlap
keyboard.setKey(key1, mb_active and (theta < 45 + ol or theta > 315 - ol))
keyboard.setKey(key2, mb_active and (theta > 45 - ol and theta < 135 + ol))
keyboard.setKey(key3, mb_active and (theta > 135 - ol and theta < 225 + ol))
keyboard.setKey(key4, mb_active and (theta > 225 - ol and theta < 315 + ol))
def radial_buttons_initial(overlap, key1, key2, key3, key4):
global x
global y
global theta
global mb_active
offset = 90
min_swipe = 10
x += mouse.deltaX
y += mouse.deltaY
if x > 0:
theta = math.atan(y/x) * 180 / math.pi + offset
elif x < 0:
theta = ( math.atan(y/x) + math.pi ) * 180 / math.pi + offset
else:
if y > 0:
theta = 90 + offset
elif y < 0:
theta = -90 + offset
else:
theta = -91 + offset
ol = overlap
if (x*x + y*y) > min_swipe*min_swipe and not mb_active:
mb_active = True
#keyboard.setPressed(key1, mb_active and (theta < 45 + ol or theta > 315 - ol))
#keyboard.setPressed(key2, mb_active and (theta > 45 - ol and theta < 135 + ol))
#keyboard.setPressed(key3, mb_active and (theta > 135 - ol and theta < 225 + ol))
#keyboard.setPressed(key4, mb_active and (theta > 225 - ol and theta < 315 + ol))
if theta < 45 + ol or theta > 315 - ol:
keyboard.setPressed(key1)
if theta > 45 - ol and theta < 135 + ol:
keyboard.setPressed(key2)
if theta > 135 - ol and theta < 225 + ol:
keyboard.setPressed(key3)
if theta > 225 - ol and theta < 315 + ol:
keyboard.setPressed(key4)
def radial_buttons_release(overlap, key1, key2, key3, key4, mb_release):
global x
global y
global theta
global mb_active
offset = 90
min_swipe = 10
x += mouse.deltaX
y += mouse.deltaY
if x > 0:
theta = math.atan(y/x) * 180 / math.pi + offset
elif x < 0:
theta = ( math.atan(y/x) + math.pi ) * 180 / math.pi + offset
else:
if y > 0:
theta = 90 + offset
elif y < 0:
theta = -90 + offset
else:
theta = -91 + offset
ol = overlap
if (x*x + y*y) > min_swipe*min_swipe and not mb_active:
mb_active = True
elif mb_active:
if mb_release:
if theta < 45 + ol or theta > 315 - ol:
keyboard.setPressed(key1)
if theta > 45 - ol and theta < 135 + ol:
keyboard.setPressed(key2)
if theta > 135 - ol and theta < 225 + ol:
keyboard.setPressed(key3)
if theta > 225 - ol and theta < 315 + ol:
keyboard.setPressed(key4)
return False
else:
return True
else:
return False
def release_buttons(key1, key2, key3, key4):
keyboard.setKeyUp(key1)
keyboard.setKeyUp(key2)
keyboard.setKeyUp(key3)
keyboard.setKeyUp(key4)
if starting:
x = 0
y = 0
theta = -1
mb_active = False
mwu_flag = False
mwd_flag = False
s = True
lmb_release_flag = False
mwd_release_flag = False
if s:
diagnostics.watch(x)
diagnostics.watch(y)
diagnostics.watch(theta)
diagnostics.watch(mb_active)
diagnostics.watch(mwu_flag)
diagnostics.watch(mwd_flag)
diagnostics.watch(lmb_release_flag)
diagnostics.watch(mwd_release_flag)
if mouse.wheelUp:
if mwu_flag:
mwu_flag = False
else:
mwu_flag = True
if mouse.wheelDown:
if mwd_flag:
mwd_flag = False
else:
mwd_flag = True
if mouse.leftButton:
#radial_buttons_initial(15, Key.A, Key.B, Key.C, Key.D)
lmb_release_flag = radial_buttons_release(15, Key.A, Key.B, Key.C, Key.D, False)
elif mouse.rightButton:
radial_buttons_initial(15, Key.E, Key.F, Key.G, Key.H)
elif mwu_flag:
radial_buttons_hold(-15, Key.I, Key.J, Key.K, Key.L)
elif mwd_flag:
#radial_buttons_hold(-15, Key.M, Key.N, Key.O, Key.P)
mwd_release_flag = radial_buttons_release(15, Key.M, Key.N, Key.O, Key.P, False)
else:
if mb_active:
# activate keys on button release
radial_buttons_release(15, Key.A, Key.B, Key.C, Key.D, lmb_release_flag)
lmb_release_flag = False
radial_buttons_release(15, Key.M, Key.N, Key.O, Key.P, mwd_release_flag)
mwd_release_flag = False
# ensure all keys are released
release_buttons(Key.A, Key.B, Key.C, Key.D)
release_buttons(Key.E, Key.F, Key.G, Key.H)
release_buttons(Key.I, Key.J, Key.K, Key.L)
release_buttons(Key.M, Key.N, Key.O, Key.P)
mb_active = False
x = 0
y = 0