Posts: 2,700
Threads: 124
Joined: Apr 2022
Reputation:
134
12-12-2022, 03:37 AM
(This post was last modified: 12-12-2022, 03:38 AM by bplus.)
(12-11-2022, 09:21 PM)RhoSigma Wrote: I never understood the sense of a silent/hidden (or what ever you wanna call) input field.
Simply don't type your password if too many suspicious creatures hanging around you.
And..., if I would be one of those creatures, then I would follow your fingers on the keyboard, so you should better get a keyboard with blank keys instead.
And there is a countermeasure for that too:
https://www.mic.com/articles/101146/rese...ory-eraser
b = b + ...
Posts: 1,616
Threads: 157
Joined: Apr 2022
Reputation:
77
12-12-2022, 03:44 AM
(This post was last modified: 12-12-2022, 04:58 AM by Pete.)
What? It's not good enough!!! Okay, try this baby out...
Change pw = 0 to pw =1 to display asterisks.
Code: (Select All) ' Single line keyboard routine for input. Excludes highlighting, cut, copy, paste.
LOCATE , 3, 1 ' Show cursor.
pw = 0 ' 1 sets "*" display on for password privacy, zero shows keyboard input.
mr = 11 ' Margin right.
start_column = POS(0)
y = CSRLIN: x = POS(0) ' Initial cursor position.
DO
_LIMIT 30
b$ = INKEY$
IF LEN(b$) THEN
string_pos = POS(0) - start_column ' Track cursor and word position.
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) + "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$(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:
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:
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
RETURN
delete:
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 POS(0) < mr THEN LOCATE , POS(0) + 1
RETURN
cursor_back:
LOCATE , POS(0) - 1
RETURN
Well, that's enough fun for me tonight. Have to go make tacos. Yum!
If eggs are brain food, Biden takes his scrambled.
Posts: 10
Threads: 1
Joined: Dec 2022
Reputation:
0
Code: (Select All) do
pete > ra7en
loop until ra7en > pete
3 out of 2 people have trouble with fractions
Posts: 1,616
Threads: 157
Joined: Apr 2022
Reputation:
77
Someone once asked me "A penny for my thoughts. I replied, and they asked for change.
Posts: 224
Threads: 7
Joined: Apr 2022
Reputation:
14
nice job showing them how it's done, Steve. Is extendedinput included with QB64PE or not yet?
Posts: 1,507
Threads: 160
Joined: Apr 2022
Reputation:
116
(12-12-2022, 06:25 AM)vince Wrote: nice job showing them how it's done, Steve. Is extendedinput included with QB64PE or not yet?
It's not, but it's part of my KeyHit library. Works with custom keyboard layouts, and unicode printing, so it's great for people with non-American keyboards.
Posts: 1,616
Threads: 157
Joined: Apr 2022
Reputation:
77
For those of you who didn't know, Vince used to work out of U.C.L.A. until his pom poms got destroyed in a sorority barbecue.
Pete
If eggs are brain food, Biden takes his scrambled.
Posts: 1,510
Threads: 53
Joined: Jul 2022
Reputation:
47
(12-12-2022, 06:54 AM)SMcNeill Wrote: It's not, but it's part of my KeyHit library. Works with custom keyboard layouts, and unicode printing, so it's great for people with non-American keyboards. Cleverly, it's also another example of telling off those people who want QB64(PE) to support a subprogram written by the user which is like "sprintf()" in C. Somehow take that function and come up with an all-BASIC version of it that replaces "PRINT USING" most of the time.
I wrote a function that randomly chooses an integer from a list. That function accepts one parameter which is a string, the contents of that string is a semicolon-separated list of values. It's because otherwise we cannot do like the extended "CHR$()" implementation in Freebasic. I have done that too and more, even one called "chrud$()" which returns an 8-character string out of a 16-digit _INTEGER64 hexadecimal value.
However, to get a password and to let the user know how important it is, a function like that "ExtendedInput$" isn't necessary. Just use "INPUT$(1)" to get each character, maybe allow only backspace and [ENTER], and don't print anything that was typed. The "sudo" password requester for many Linux distros is a bit permissive IMHO.
Posts: 224
Threads: 7
Joined: Apr 2022
Reputation:
14
(12-12-2022, 08:37 AM)mnrvovrfc Wrote: However, to get a password and to let the user know how important it is, a function like that "ExtendedInput$" isn't necessary. Just use "INPUT$(1)" to get each character, maybe allow only backspace and [ENTER], and don't print anything that was typed. The "sudo" password requester for many Linux distros is a bit permissive IMHO.
hey don't get too ahead of yourself there. Sometimes it is the better programming practice to use something that has been stress tested by our user base for YEARS now. Its results speak for themselves. You try to get too clever for your own good by spinning it yourself you end up going full Pete
Posts: 1,616
Threads: 157
Joined: Apr 2022
Reputation:
77
..Or end up doing it over and going full re-Pete.
Two schools of thought here, and both have merit.
1) Do it yourself to build confidence in your coding ability. Whatever the style, if it works, it works.
2) Use other people's libraries and routines. Faster, hopefully proven, and you get to spend more time on other part of your project.
The C/C++ community and I hear the Python community are big on telling newbies to just use libraries. I drove those C people nuts when I wanted to make a custom keyboard input routine in C/C++. I did it, but getting help was a bit of a struggle, because hardly anyone there knew anything about a non-library approach.
For me, my custom keyboard routines are fun to build and always allow complete customization and flow-through events. Can't do that, no matter how much better LINE INPUT gets.
Just my 2-cent, and since those pennies are from the Roman Empire Era, they're actually worth something.
Pete
|