Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Typing for chat via Keyboard input

Author
Message
Rick the Programmer
20
Years of Service
User Offline
Joined: 23rd Mar 2004
Location: Maryland
Posted: 6th Mar 2014 01:13
It's always been on my to-do list and I finally did it. This is a function to read keyboard input through typing, storing the data in a string. It's capable of allowing most conversations on a standard QWERTY keyboard.

It's used as follows:

char$ = KB_Input(char$)

char$ being the local string variable storing your keyboard input





I created this short program with a simplified main loop that can be copied into your compiler with no added files. When you execute, just start typing and your keystrokes will be caught in a non-clunky fashion and displayed on-screen. When you hit "Enter," the current input field is saved into the chat log and displayed on screen below the text field.

Demo source:


I hope this helps anyone looking for this kind of code in the future!

Ask not for whom the bell tolls;
It tolls for ye!
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 11th Mar 2014 20:42 Edited at: 11th Mar 2014 20:44
This is an elegant solution to the problem. But I take it you haven't heard of the entry$ command?



EDIT: Also, the proper grammar in your sig is "it tolls for thee"

Rick the Programmer
20
Years of Service
User Offline
Joined: 23rd Mar 2004
Location: Maryland
Posted: 11th Mar 2014 23:01 Edited at: 11th Mar 2014 23:10
No, I hadn't been familiar with that command. That simplifies it wonderfully, lol. Between my code and your response, this thread should be very helpful for newbies researching the topic. That's exactly the kind of command and example I had been searching for. Thank you.

I'll consider the work done on the function to be part of a greater learning experience XD

I've been aware of the misquote on the sig for a while. It still reads well, though, and I use it for inspiration... like a metaphor for that part of your code that you saw flaws in but never fixed because it worked well enough. It's a reminder to write code properly before moving on!

Ask not for whom the bell tolls;
It tolls for ye!

Login to post a reply

Server time is: 2024-04-24 06:40:13
Your offset time is: 2024-04-24 06:40:13