Giter Site home page Giter Site logo

Comments (4)

ppizarror avatar ppizarror commented on May 21, 2024

Sometimes the key events does not correspond to the keyboard events, so I added the method check_key that verify KEYDOWN is valid. For testing purposes you can raise an KEYDOWN event by adding 'test' to the dict:

pygame.event.Event(pygame.KEYDOWN, {"key"=pygame.K_DOWN, "test"=true})

pygame-menu/test/_utils.py

Lines 114 to 150 in 1e40ec7

def key(key, char='', inlist=True, keydown=False, keyup=False, testmode=True):
"""
Create a keyboard event.
:param key: Key to press
:type key: int
:param char: Char representing the key
:type char: basestring
:param inlist: Return event in a list
:type inlist: bool
:param keydown: Event is keydown
:type keydown: bool
:param keyup: Event is keyup
:type keyup: bool
:param testmode: Key event is in test mode
:type testmode: bool
:return: Event
:rtype: pygame.event.Event
"""
if keyup and keydown:
raise ValueError('keyup and keydown cannot be active at the same time')
if keydown == keyup and not keydown:
raise ValueError('keyup and keydown cannot be false at the same time')
event = -1
if keydown:
event = pygame.KEYDOWN
if keyup:
event = pygame.KEYUP
event_obj = pygame.event.Event(event,
{'key': key,
'test': testmode,
})
if len(char) == 1:
event_obj.dict['unicode'] = char
if inlist:
event_obj = [event_obj]
return event_obj

from pygame-menu.

ppizarror avatar ppizarror commented on May 21, 2024

In some cases if you press a key too fast and release it the event state of pygame stills recognizes the last pressed key as pressed (the KEYUP is ignored). That bug was very common in TextInput widget

from pygame-menu.

ppizarror avatar ppizarror commented on May 21, 2024

If you want we can rename 'test' to another clearer name

from pygame-menu.

anxuae avatar anxuae commented on May 21, 2024

Ok for me, I understand now the reason. I will use the key test for my custom event.
The name is ok, see in your test why you call it like that.

Thanks

from pygame-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.