3

I try to detect if both CTRL is pressed simultaneously

import pygame
pygame.init()

screen = pygame.display.set_mode((100,100))

run = True
while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RCTRL
                print("RIGHT CTRL pressed")
            if event.key == pygame.K_LCTRL
                print("LEFT CTRL pressed")

Also tried:

if event.type == pygame.KEYDOWN:
    if pygame.key.get_mods() & pygame.KMOD_RCTRL:
        print("RIGHT CTRL pressed")
    if pygame.key.get_mods() & pygame.KMOD_LCTRL:
        print("LEFT CTRL pressed")

Also tried:

if event.type == pygame.KEYDOWN:
    if pygame.key.get_mods() & pygame.KMOD_LCTRL and pygame.key.get_mods() & pygame.KMOD_RCTRL:
        print("LEFT & RIGHT CTRL pressed")

None of these worked.

Can someone help? Thanks.

Zoltan
  • 533
  • 4
  • 18
  • 1
    They seem to be not detected at all. You can only press one at a time, if you have both hold done, no key events are produced for me. – MegaIng May 17 '18 at 17:56
  • I've had a play around with this and been unable to detect simultaneous presses of the left and right control keys. Note also that the KEYDOWN `event` has a `mods` parameter so you needn't call `get_mods()` multiple times. It looks to me that when a duplicate mod key is pressed, it is ignored until all keys are released. – import random May 17 '18 at 22:55
  • Thank you for looking into it. – Zoltan May 18 '18 at 13:55

1 Answers1

0

Replace KMOD_LCTRL with K_LCTRL