Heres the Class I made for User input as the dbEntry() command was a lackluster way to gather userinput
class _TextInput {
public:
std::string UserInput;
std::string LastInput;
int InputTotal;
// For Control over amount input
bool InputOnceFlag;
// For Control over Delay Before Key repeats
int TimeToAdd;
_TextInput() : InputTotal(0), InputOnceFlag(false)
{ //LastInput = '\0';
TimeToAdd = 0;
}
virtual ~_TextInput() {}
void User_Input_Text() {
char* InputBuffer = dbInKey();
// Check For Backspace
if(dbScanCode() == 14)
{ // Create Eraser
std::string::iterator eraser = UserInput.end();
// Don't Need this Here, but its nice to free up memory
// Delete Memory Allocated by dbInKey()
delete [] InputBuffer; InputBuffer = 0;
if(InputOnceFlag)
{ // Check Timer
if(TimeToAdd <= dbTimer())
{ // If not begining, decrement back one
// so eraser isn't at end() end() = '\0'
if(eraser != UserInput.begin())
{
eraser--;
// Erase Last Char in String
UserInput.erase(eraser);
// Repeat Rate
TimeToAdd = dbTimer() + 50;
}
}
}
else // InputOnceFlag = False
{
if(eraser != UserInput.begin())
{
eraser--;
UserInput.erase(eraser);
// Set Input Once Flag
InputOnceFlag = true;
// Deley until Repeat
// 1 Sec
TimeToAdd = dbTimer() + 1000;
}
}
}
else if(*InputBuffer != '\0')
{
std::string TestBuffer = InputBuffer;
// If Same As last Input
if(LastInput == TestBuffer)
{ // If it has Already been input once
if(InputOnceFlag)
{ // If Its Time to Add this char to the String
if(TimeToAdd <= dbTimer())
{
InputTotal++;
UserInput += TestBuffer;
// Repeat Rate
TimeToAdd = dbTimer() + 50;
//LastInput == TestBuffer;
}
}
else // InputOnceFlag == False
{
InputTotal++;
UserInput += TestBuffer;
// Input Once
InputOnceFlag = true;
// Sec's To to Wait till repeating this char in the string
// 1 sec
TimeToAdd = dbTimer() + 1000;
}
}
else // InputBuffer != LastInput
{
InputTotal++;
UserInput += TestBuffer;
LastInput = TestBuffer;
InputOnceFlag = true;
// Set To to Wait till repeating this char in the string
// 1 sec
TimeToAdd = dbTimer() + 1000;
}
}
else // No Key Pressed InputBuffer == '\0'
{
// reset InputOnceFlag
if(InputOnceFlag == true) InputOnceFlag = false;
// reset Timer
if(TimeToAdd != 0) TimeToAdd = 0;
}
// Delete Memory Allocated by dbInKey()
if(InputBuffer != 0)
{ delete [] InputBuffer; InputBuffer = 0;}
}
void ClearInputString() {
UserInput.clear();
InputTotal = 0;
}
}; // class _TextInput
why does it keep changing '\0' sequences to '?' in the code snippet?
You have to write the code to Handle Enter key and so forth, but you can just have it so if enter is pressed you copy the string out of this class to where ever you want it and clear the UserInput sring for use again somewhere else.
Taco Justice