1 registered members (TipmyPip),
18,546
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Adding mouse_left support for inkey
#317531
04/01/10 06:15
04/01/10 06:15
|
Joined: Aug 2001
Posts: 2,320 Alberta, Canada
William
OP
Expert
|
OP
Expert
Joined: Aug 2001
Posts: 2,320
Alberta, Canada
|
I'm currently using a function to stop inkey when I hit the left mouse button.
However, this does not properly store the string as it would if I hit enter or tab.
For example, if I were to type "ggg" and then end this prematurely:
str_cpy(gonline_uname," "); result = inkey(gonline_uname); //- enter online name
The resulting string would be "ggg____________"
Whereas the underline is actual spaces(this forum wont let me display spaces there??). However, if I hit enter instead, it would be:
"ggg"
This would be fine if I could find a way to know how to trunc the spaces, but I do not. Could we have inkey_active = 0; act the same way as if we ended the inkey operation normally? Thanks.
|
|
|
Re: Adding mouse_left support for inkey
[Re: William]
#317574
04/01/10 11:23
04/01/10 11:23
|
Joined: Feb 2009
Posts: 3,207 Germany, Magdeburg
Rei_Ayanami
Expert
|
Expert
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
|
Seconded, i really need this too.
edit: for me the string always(!) has "spaces" at the end, even if the user presses enter.
Last edited by Rei_Ayanami; 04/01/10 11:28.
|
|
|
Re: Adding mouse_left support for inkey
[Re: pararealist]
#317622
04/01/10 14:54
04/01/10 14:54
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Or you can just trim off the end spaces.
int str_rtrim(STRING* input)
{ int trunc, pos; for(pos=str_len(input)-1; pos>0; pos--)
{ if((input.chars)[pos]!=32)
{ str_trunc(input, (trunc=str_len(input)-pos-1));
break;
} }
return(trunc);
}
This function trims off any trailing spaces (on the right-hand end of the string), and it returns the number of trimmed spaces if you want to know...
Last edited by EvilSOB; 04/01/10 21:21. Reason: clarified variable names
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Adding mouse_left support for inkey
[Re: William]
#317705
04/01/10 21:16
04/01/10 21:16
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Basically, it starts at the LAST character of the total string, and checks to see if it is a space(==32). If it is NOT a space-character, it truncates everything 'beyond' this point, and exits the loop. If it IS a space-character, it loops over to checks the next character back, et al.
note: variable "pos' is which byte it is currently checking, and variable 'trunc' gets set to how many characters got truncated.
[EDIT] Ive just changed to snippet so the variable names are more descriptive...
Last edited by EvilSOB; 04/01/10 21:24.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|