6502 machine code (C64), 22 21 bytes
0e 08 20 9f ff 20 e4 ff f0 f8 c9 0d f0 01 a9 60 20 d2 ff 50 ed
Usage: SYS 2062
Commented disassembly listing (ACME), you can uncomment the first three commented lines to launch with RUN
once loaded:
!cpu 6502
!to "password2.prg",cbm
;* = $0801 ; BASIC starts at #2049
;!byte $0d,$08,$dc,$07,$9e,$20,$32,$30 ; BASIC to load $c000
;!byte $36,$32,$00,$00,$00 ; inserts BASIC line: 2012 SYS 2062
GETIN = $FFE4
SCNKEY = $FF9F
CHROUT = $FFD2
* = $080e
keyScan:
jsr SCNKEY ; get key
jsr GETIN ; put key in A
beq keyScan ; if no key pressed loop
cmp #13 ; check if RETURN was pressed
beq $081b ; if true go to operand of next instruction (#$60 = rts)
lda #$60 ; load char $60 into accumulator
jsr CHROUT ; print it
bvc keyScan ; loop
Comments:
- I haven't found anything in the docs, but it seems that, after the GETIN call, beq branches only where no new key presses have been recorded;
- Using #$60 as output char, that byte can be reused as "rts" instruction when RETURN is pressed.
tkinter
允许使用我们的自定义输入字段(例如HTML中的),这样在按下Enter键时程序不会终止,但是在您关闭Entry
“窗口”时(Windows 上为X,在Mac 上为cmd
+W
)。