Öncelikle herkese merhabalar yeni yeni Python öğreniyorum ve öğrenirken de kendimce bir program yazmaya çalışıyorum. İnternetten araştırarak bulduğum 2 kod var fakat bunlardan hangisini üste koyarsam o çalışıyor, diğeri çalışmıyor. Bunların ikisini aynı anda nasıl çalıştırabilirim? (neden çalışmadığını da açıklarsanız sevinirim.)
[CODE lang="python" title="Kod 1"]with keyboard.GlobalHotKeys({
'<home>': on_activate,
'<ctrl>+<alt>+1': on_activate_a,
'<ctrl>+<alt>+2': on_activate_b,
'<ctrl>+<alt>+3': on_activate_c,
'<ctrl>+<alt>+4': on_activate_d,
'<ctrl>+<alt>+5': on_activate_e}) as h:
h.join()[/CODE]
[CODE lang="python" title="Kod 2"]def on_click(*args):
global leftPressed, rightPressed, bothPressed.
# print(args)
if args[-1]:
# mouse key pressed.
print('The "{}" mouse key has held down'.format(args[-2].name))
if args[-2].name == "left":
leftPressed = True.
elif args[-2].name == "right":
rightPressed = True.
if leftPressed and rightPressed:
# if both left and right are pressed.
bothPressed = True.
print("bothpressed=", bothPressed)
elif not args[-1]:
# mouse key released.
print('The "{}" mouse key is released'.format(args[-2].name))
if args[-2].name == "left":
leftPressed = False.
elif args[-2].name == "right":
rightPressed = False.
# as one key has been released, both are no longer pressed.
bothPressed = False.
print("bothpressed=", bothPressed)
# Open Listener for mouse key presses.
with mouse.Listener(on_click=on_click) as listener:
# Listen to the mouse key presses.
listener.join()[/CODE]
[CODE lang="python" title="Kod 1"]with keyboard.GlobalHotKeys({
'<home>': on_activate,
'<ctrl>+<alt>+1': on_activate_a,
'<ctrl>+<alt>+2': on_activate_b,
'<ctrl>+<alt>+3': on_activate_c,
'<ctrl>+<alt>+4': on_activate_d,
'<ctrl>+<alt>+5': on_activate_e}) as h:
h.join()[/CODE]
[CODE lang="python" title="Kod 2"]def on_click(*args):
global leftPressed, rightPressed, bothPressed.
# print(args)
if args[-1]:
# mouse key pressed.
print('The "{}" mouse key has held down'.format(args[-2].name))
if args[-2].name == "left":
leftPressed = True.
elif args[-2].name == "right":
rightPressed = True.
if leftPressed and rightPressed:
# if both left and right are pressed.
bothPressed = True.
print("bothpressed=", bothPressed)
elif not args[-1]:
# mouse key released.
print('The "{}" mouse key is released'.format(args[-2].name))
if args[-2].name == "left":
leftPressed = False.
elif args[-2].name == "right":
rightPressed = False.
# as one key has been released, both are no longer pressed.
bothPressed = False.
print("bothpressed=", bothPressed)
# Open Listener for mouse key presses.
with mouse.Listener(on_click=on_click) as listener:
# Listen to the mouse key presses.
listener.join()[/CODE]