anykeys.py

Created by mobluse

Created on October 31, 2024

1010 Bytes

Anykeys shows which keys you press and you can press several at the same time. The last key pressed is shown in the lower left corner. In the emulators on the NumWorks site only a few buttons on your emulator’s physical keyboard work: e.g. Tab (Toolbox), Backspace, Enter (EXE), Shift, Esc (Back), Alt+x (exp), Alt+v (var), Alt+e (EE), Alt+r (sqrt), Alt+p (pi), Alt+Shift+2 (**2), Alt+Shift+e (Back), and the arrow keys, but of these only Tab, Enter, Shift, and the arrow keys work in Anykeys. The Back/Escape key interrupts the program. None of the JavaScript emulator’s screen keys works with Anykeys. In the emulator for iPhone only the OK button works. It works well with the real calculator, but if you press many keys some non pressed keys might be added or removed - this is probably due to the keyboard matrix circuit.

On my UK keyboard in Linux these key combinations also work in the Python shell: AltGr+i (→), AltGr+o (ø), AltGr+p (þ), AltGr+a (æ), AltGr+d (ð), AltGr+s (ß), AltGr+Shift+q (Ω), AltGr+Shift+f (ª), AltGr+Shift+m (º), AltGr+Shift+0 (°). All other UK keyboard keys work normally except: ¬, £, ^ (**), ¹, ², ³, €, ½, ¾, ¡, ⅛, ¼, ⅜, ⅝, ⅞, ™, ±, ¿.


import kandinsky as k
import time
import ion
def ds0(s,p):
  k.draw_string(s,p[0],p[1],"yellow","blue")
def ds1(s,p):
  k.draw_string(s,p[0],p[1],"blue","yellow")
def run():
  ks=dir(ion)
  del ks[:2]
  x,y=0,3
  cs=[]
  es=[]
  fr=k.fill_rect
  fr(0,0,320,240,"blue")
  for i in range(len(ks)):
    ks[i]=ks[i][4:]
    fr(x,y,20,19,"red")
    x+=1
    ds0(ks[i],(x,y))
    cs.append((x,y))
    es.append(eval("ion.KEY_"+ks[i]))
    if i<8:
      x+=320//8
      if i==7:
        x=0
        y+=20+10
    elif 26<=i:
      x+=320//5
      if (i-30)%5==0:
        x=0
        y+=20
    else:
      x+=320//6
      if (i-13)%6==0:
        x=0
        y+=20
        if i==25:
          y+=10
  ts=time.sleep
  ts(1)
  p="Press any keys!"
  ds1(p,((32-len(p))*10,11*18+3))
  ik=ion.keydown
  while 1:
    for i in range(len(ks)):
      if ik(es[i]):
        fr(0,11*18+3,170,18,"blue")
        ds1(ks[i],(0,11*18+3))
        ds1(ks[i],cs[i])
      else:
        ds0(ks[i],cs[i])
    ts(0.0001)
run()