drawinput.py

Created by squarepoint

Created on November 30, 2022

757 Bytes

Aren’t you tired of writing inputs in text mode? Well now you can write them in graphic mode too! Without the input() function!!!!

HOW IT WORKS: Apparently, each key value such as KEY_OK is actually a variable set to an integer! That means you can cycle through a list of numbers and detect if each key is pressed! Isn’t that amazing?


from kandinsky import fill_rect as rct,draw_string as txt
from ion import keydown
from time import sleep

KEYS=[18,"a",19,"b",20,"c",21,"d",22,"e",23,"f",24,"g",25,"h",26,"i",27,"j",28,"k",29,"l",30,"m",31,"n",32,"o",33,"p",34,"q",36,"r",37,"s",38,"t",39,"u",40,"v",42,"w",43,"x",44,"y",45,"z",46," "]
WHT,ORG=(255,255,255),(255,150,50)

answer=""

def dinput():
  global answer
  if keydown(17):
    answer=answer[:-1]
  for i in range(len(KEYS)/2):
    if keydown(KEYS[i*2]):
      answer+=KEYS[i*2+1]
      break

while True:
  rct(0,0,320,222,ORG)
  txt("DrawInput",115,50,WHT,ORG)
  txt("By squarepoint",90,70,WHT,ORG)
  txt("Input in graphic mode!",50,100,WHT,ORG)
  txt(answer,160-len(answer)*5,120,WHT,ORG)
  sleep(0.05)
  dinput()

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.