Home > database >  How to implement CMD C and CMD V in pygame
How to implement CMD C and CMD V in pygame

Time:04-04

I have working example which copies user input running at Windows

text=""
if event.key == pygame.K_c and pygame.key.get_mods() & pygame.KMOD_CTRL and not pygame.key.get_mods() & pygame.KMOD_ALT:
    print("pressed CTRL-C as an event")
    pyperclip.copy(text)

but not at mac, I could not find any string representing Mac "command" key in documentation https://www.pygame.org/docs/ref/key.html and thus have hard time implementing copying there. Does anyone know how to solve this?

CodePudding user response:

pygame.KMOD_META represents the command key on macOS. So, your code would look like:

if event.key == pygame.K_c and pygame.key.get_mods() & pygame.KMOD_META and not pygame.key.get_mods() & pygame.KMOD_ALT:
    print("pressed CMD-C as an event")
  • Related