Silent pw entry not working
#33
Hey Vince. How about we add Ctrl + arrows, with highlighting, Shift with highlighting, cut, copy, and paste?

Code: (Select All)
DIM SHARED shift%
' Single line keyboard routine for input.
LOCATE , 3, 1 ' Show cursor.
pw = 0 ' 1 sets "*" display on for password privacy, zero shows keyboard input.
mr = 31 ' Margin right.
start_column = POS(0)
y = CSRLIN: x = POS(0) ' Initial cursor position.
DO
    _LIMIT 30
    string_pos = POS(0) - start_column ' Track cursor and word position.
    LOCATE 5, 3: PRINT string_pos; "  ";: LOCATE y, x

    CALL kb_mse(b$)

    IF LEN(b$) THEN

        SELECT CASE b$
            CASE CHR$(27) ' Esc key.
                SYSTEM
            CASE CHR$(13) ' Enter key.
                EXIT DO
            CASE CHR$(8) ' Backspace key.
                IF string_pos > 0 THEN GOSUB backspace
            CASE CHR$(0) + "S" ' Delete key.
                GOSUB delete
            CASE CHR$(0) + "M" ' Arrow right key.
                IF string_pos < LEN(word$) THEN GOSUB cursor_forward
            CASE CHR$(0) + "K" ' Arrow left key.
                IF string_pos > 0 THEN GOSUB cursor_back
            CASE CHR$(0) + "t" ' Ctrl + Arrow right key.
                IF string_pos < LEN(word$) THEN GOSUB ctrl_rt
            CASE CHR$(0) + "s" ' Ctrl + Arrow left key.
                IF string_pos > 0 THEN GOSUB ctrl_lt
            CASE CHR$(0) + "G" ' Home
                LOCATE , start_column
            CASE CHR$(0) + "O" ' End
                LOCATE , start_column - 1 + LEN(word$)
                IF POS(0) < mr THEN LOCATE , POS(0) + 1
            CASE CHR$(0) + "R" ' Insert/overwrite toggel
                ovw = 1 - ovw
                IF ovw = 0 THEN LOCATE , , 1, 7, 7 ELSE LOCATE , , 1, 7, 30
            CASE CHR$(22) ' Ctrl + V - Paste
                IF LEN(_CLIPBOARD$) THEN GOSUB paste
            CASE CHR$(3) ' Ctrl + C - Copy
                GOSUB copy
            CASE CHR$(24) ' Ctrl + X - Cut
                GOSUB cut
            CASE CHR$(32) TO "z"
                IF string_pos + start_column < mr THEN GOSUB print_chr
        END SELECT
        y = CSRLIN: x = POS(0) ' Track cursor.
    END IF
LOOP
END

print_chr:
IF hl THEN COLOR 7, 0: hl = 0
SELECT CASE ovw
    CASE 0
        IF start_column + LEN(word$) < mr THEN
            word$ = MID$(word$, 1, string_pos) + b$ + MID$(word$, string_pos + 1)
            LOCATE , start_column: PRINT SPACE$(LEN(word$) + 1);
            LOCATE , start_column
            IF pw THEN PRINT STRING$(LEN(word$), "*"); ELSE PRINT word$;
            LOCATE , x + 1
        END IF
    CASE ELSE
        word$ = MID$(word$, 1, string_pos) + b$ + MID$(word$, string_pos + 1)
        IF pw THEN PRINT "*"; ELSE PRINT b$;
END SELECT
RETURN

backspace:
IF hl THEN COLOR 7, 0: hl = 0
word$ = MID$(word$, 1, string_pos - 1) + MID$(word$, string_pos + 1)
LOCATE , start_column: PRINT SPACE$(LEN(word$) + 1);
LOCATE , start_column
IF pw THEN PRINT STRING$(LEN(word$), "*"); ELSE PRINT word$;
LOCATE , x - 1
hl = 0
RETURN

delete:
IF hl THEN COLOR 7, 0: hl = 0
word$ = MID$(word$, 1, string_pos) + MID$(word$, string_pos + 2)
LOCATE , start_column: PRINT SPACE$(LEN(word$) + 1);
LOCATE , start_column
IF pw THEN PRINT STRING$(LEN(word$), "*"); ELSE PRINT word$;
LOCATE , x
RETURN

cursor_forward:
IF shift% AND POS(0) < mr THEN
    IF hl < 0 THEN COLOR 7, 0 ELSE COLOR 0, 7
    hl = hl + 1
    IF pw THEN PRINT "*"; ELSE PRINT MID$(word$, string_pos + 1, 1);
    COLOR 7, 0
ELSE
    IF hl THEN GOSUB hl_off
    IF POS(0) < mr THEN LOCATE , POS(0) + 1
END IF
RETURN

cursor_back:
IF shift% THEN
    IF hl > 0 THEN COLOR 7, 0 ELSE COLOR 0, 7
    hl = hl - 1
    LOCATE , POS(0) - 1
    IF pw THEN PRINT "*"; ELSE PRINT MID$(word$, string_pos, 1);
    COLOR 7, 0
ELSE
    IF hl THEN GOSUB hl_off
END IF
LOCATE , POS(0) - 1
RETURN

ctrl_rt:
i = 0
DO
    i = i + 1 ' Do not use this variable in cursor_forward routine.
    GOSUB cursor_forward
    string_pos = POS(0) - start_column
LOOP UNTIL MID$(word$, string_pos, 1) = " " OR string_pos >= LEN(word$)
RETURN

ctrl_lt:
i = 0
DO
    i = i - 1 ' Do not use this variable in cursor_forward routine.
    GOSUB cursor_back
    string_pos = POS(0) - start_column
LOOP UNTIL MID$(word$, string_pos, 1) = " " OR POS(0) = start_column
RETURN

hl_off:
LOCATE , start_column
COLOR 7, 0
IF pw THEN PRINT STRING$(LEN(word$), "*"); ELSE PRINT word$;
LOCATE , x
hl = 0
RETURN

cut:
SELECT CASE hl
    CASE IS > 0
        _CLIPBOARD$ = MID$(word$, string_pos + 1 - hl, hl)
        j = POS(0) - hl
        LOCATE , start_column
        PRINT SPACE$(LEN(word$));
        word$ = MID$(word$, 1, string_pos - hl) + MID$(word$, string_pos + 1)
        LOCATE , start_column
        IF pw THEN PRINT STRING$(LEN(word$), "*"); ELSE PRINT word$;
        LOCATE , j
    CASE 0
        ' Do nothing
    CASE IS < 0
        _CLIPBOARD$ = MID$(word$, string_pos + 1, ABS(hl))
        LOCATE , start_column
        PRINT SPACE$(LEN(word$));
        word$ = MID$(word$, 1, string_pos) + MID$(word$, string_pos + 1 + ABS(hl))
        LOCATE , start_column
        IF pw THEN PRINT STRING$(LEN(word$), "*"); ELSE PRINT word$;
        LOCATE , start_column + string_pos
END SELECT
RETURN

copy:
SELECT CASE hl
    CASE IS > 0
        _CLIPBOARD$ = MID$(word$, string_pos + 1 - hl, hl)
    CASE 0
        ' Do nothing
    CASE IS < 0
        _CLIPBOARD$ = MID$(word$, string_pos + 1, ABS(hl))
END SELECT
RETURN

paste:
tmp$ = _CLIPBOARD$
IF start_column + LEN(word$) + LEN(tmp$) < mr THEN
    word$ = MID$(word$, 1, string_pos) + tmp$ + MID$(word$, string_pos + 1)
    LOCATE , start_column
    IF pw THEN PRINT STRING$(LEN(word$), "*"); ELSE PRINT word$;
    LOCATE , start_column + string_pos + LEN(tmp$)
END IF
RETURN

SUB kb_mse (b$)
    IF _KEYDOWN(100303) OR _KEYDOWN(100304) THEN shift% = -1 ELSE IF shift% THEN shift% = 0
    _LIMIT 30
    b$ = INKEY$
END SUB


Pete
If eggs are brain food, Biden takes his scrambled.
Reply


Messages In This Thread
Silent pw entry not working - by Ra7eN - 12-11-2022, 02:06 PM
RE: Silent pw entry not working - by NasaCow - 12-11-2022, 02:30 PM
RE: Silent pw entry not working - by Ra7eN - 12-11-2022, 02:33 PM
RE: Silent pw entry not working - by Pete - 12-11-2022, 03:29 PM
RE: Silent pw entry not working - by mnrvovrfc - 12-11-2022, 03:44 PM
RE: Silent pw entry not working - by Pete - 12-11-2022, 05:03 PM
RE: Silent pw entry not working - by Ra7eN - 12-11-2022, 05:49 PM
RE: Silent pw entry not working - by Ra7eN - 12-11-2022, 05:47 PM
RE: Silent pw entry not working - by Pete - 12-11-2022, 06:01 PM
RE: Silent pw entry not working - by RhoSigma - 12-11-2022, 09:21 PM
RE: Silent pw entry not working - by mnrvovrfc - 12-11-2022, 09:33 PM
RE: Silent pw entry not working - by Pete - 12-11-2022, 11:28 PM
RE: Silent pw entry not working - by SMcNeill - 12-11-2022, 11:57 PM
RE: Silent pw entry not working - by Pete - 12-12-2022, 12:26 AM
RE: Silent pw entry not working - by SMcNeill - 12-12-2022, 12:42 AM
RE: Silent pw entry not working - by Pete - 12-12-2022, 01:53 AM
RE: Silent pw entry not working - by SMcNeill - 12-12-2022, 02:04 AM
RE: Silent pw entry not working - by Pete - 12-12-2022, 02:57 AM
RE: Silent pw entry not working - by Ra7eN - 12-12-2022, 03:17 AM
RE: Silent pw entry not working - by Ra7eN - 12-12-2022, 03:22 AM
RE: Silent pw entry not working - by bplus - 12-12-2022, 03:37 AM
RE: Silent pw entry not working - by Pete - 12-12-2022, 03:44 AM
RE: Silent pw entry not working - by Ra7eN - 12-12-2022, 05:18 AM
RE: Silent pw entry not working - by Pete - 12-12-2022, 06:13 AM
RE: Silent pw entry not working - by vince - 12-12-2022, 06:25 AM
RE: Silent pw entry not working - by SMcNeill - 12-12-2022, 06:54 AM
RE: Silent pw entry not working - by mnrvovrfc - 12-12-2022, 08:37 AM
RE: Silent pw entry not working - by Pete - 12-12-2022, 06:58 AM
RE: Silent pw entry not working - by vince - 12-12-2022, 05:47 PM
RE: Silent pw entry not working - by Pete - 12-12-2022, 06:27 PM
RE: Silent pw entry not working - by Pete - 12-13-2022, 02:02 AM
RE: Silent pw entry not working - by Pete - 12-13-2022, 02:04 AM
RE: Silent pw entry not working - by vince - 12-13-2022, 02:12 AM
RE: Silent pw entry not working - by Pete - 12-13-2022, 02:21 AM
RE: Silent pw entry not working - by SMcNeill - 12-13-2022, 09:12 AM
RE: Silent pw entry not working - by Pete - 12-13-2022, 10:29 AM
RE: Silent pw entry not working - by mnrvovrfc - 12-13-2022, 12:19 PM
RE: Silent pw entry not working - by mnrvovrfc - 12-13-2022, 11:10 AM
RE: Silent pw entry not working - by Ra7eN - 12-14-2022, 10:24 PM
RE: Silent pw entry not working - by Ra7eN - 12-14-2022, 10:26 PM
RE: Silent pw entry not working - by SMcNeill - 12-14-2022, 11:24 PM
RE: Silent pw entry not working - by Ra7eN - 12-15-2022, 12:41 AM
RE: Silent pw entry not working - by Pete - 12-21-2022, 12:32 AM
RE: Silent pw entry not working - by bplus - 12-21-2022, 04:51 PM
RE: Silent pw entry not working - by Pete - 12-21-2022, 05:14 PM
RE: Silent pw entry not working - by bplus - 12-21-2022, 05:27 PM



Users browsing this thread: 13 Guest(s)