ion_plus.py

Created by loic-azavant

Created on March 27, 2023

792 Bytes

ajoute deux fonctions:

keyinput(key, value=None): cette fonction renvoie True seulement à l’instant ou elle est pressée. Si on recupère la valeur de key avant l’ajout de la fonction, on peut l’ajouter pour eviter de faire appel une nouvelle fois a la fonction keydown() de ion pour eviter du lag

keydowntimed(key, value=None, delay=delay): Cette fonction renvoie True si la touches est pressée toutes les delay secondes. l’argument value a la meme fonction que au dessus.


from math import *
from ion import *
from time import *

keys = {}

def keyinput(key,value=None):
  if value!=None:
    keyPressed = value
  else:
    keyPressed = keydown(key)
  if not key in keys:
    keys[key] = False
  if keyPressed and not keys[key]:
    keys[key] = True
    return True
  if keys[key]:
    if not keyPressed:
      keys[key] = False
    return False
  return False

delay = 0.15

def newDelay(new_delay):
  global delay
  delay = new_delay

keyDelayed = {}

def keydowntimed(key,value=None, delay=delay):
  if value!=None:
    keyPressed=value
  else:
    keyPressed = keydown(key)
  if not key in keyDelayed:
    keyDelayed[key] = 0
  if keyPressed and monotonic()-keyDelayed[key]>delay:
    keyDelayed[key] = monotonic()
    return True
  return False

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.