Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,493 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: inchar with more than one character and inchar_active [Re: Lukas] #385085
10/12/11 15:00
10/12/11 15:00
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, I only saw your idea with the global string after I posted the first response. You can handle backspaces with inkey the same way as with inchar. You just need to check the return value of the function.

Re: inchar with more than one character and inchar_active [Re: jcl] #385087
10/12/11 15:09
10/12/11 15:09
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline OP

Programmer
Lukas  Offline OP

Programmer

Joined: May 2007
Posts: 2,043
Germany
But inkey doesn't return when backspace is pressed, only when it's aborted e.g. with enter. o.O
inchar, however, returns and the string is then a space, and I can tell it was a backspace with key_lastpressed. Btw, I think this behaviour isn't even documented in the manual...

Re: inchar with more than one character and inchar_active [Re: Lukas] #385132
10/13/11 11:31
10/13/11 11:31
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
You're right, the editing keys are not returned. Would it help you when we implement a variable that contains the key code of the last key during inkey()?

Re: inchar with more than one character and inchar_active [Re: jcl] #385146
10/13/11 14:22
10/13/11 14:22
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline OP

Programmer
Lukas  Offline OP

Programmer

Joined: May 2007
Posts: 2,043
Germany
Well, it might help at some point, but it certainly wouldn't suffice to enable me using inkey() for LBGUI keeping all features for the editboxes.

The first problem would be that I'm pretty sure that inkey accepts more than one key per frame, right? So if I'm unlucky, I might just miss a backspace.

Also, it would be no real solution to disable backspaces, because it would still remove the last character of the inkey string, and there would be no way to prevent that, especially not if the last character and the inkey were hit in the same frame.


I think the easiest solution would be a list / an array that keeps the last, let's say 32 inputs of the inkey() function and a variable that keeps track of how many inputs were made.
For example, if I'd write "Gamestudio", then delete the "o", then write "^^" I'd get the following list:
"G","a","m","e","s,"t",u","d","i","o",backspace,"^^"
For the backspace or other keys, you could maybe use special characters or a wrapper struct.
That would have the advantage that I wouldn't have to change so much in the code, as I could just use the inputs like the inchar returns. I could make my editbox ignore the backspace. Also, I wouldn't have to care where the inkey cursor is and I don't have to interpret what's in the inkey string, I'd just get the left-arrow/right-arrow events and could handle them like I already do.

This would work even better if there was a way to make the abort keys (like enter, ESC, F1-12) not abort inkey, so I can handle these myself.
I'd also like to be able to make inkey not disable any key variables or events.

Re: inchar with more than one character and inchar_active [Re: Lukas] #385177
10/14/11 07:30
10/14/11 07:30
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
Lukas: if you want a quick solution. I would really suggest you to overload the engine message function (on_message). In the message loop you get ALL windows key messages and save them on your own way. Please check WM_KEYDOWN and the WM_CHAR message.

This solution will always be much more flexible than any way gamestudio will offer to you.

The only really important thing is to return the orginal message function afterwards (so that the engine is informed about the keystroke).

References:
WM_KEYDOWN: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280(v=vs.85).aspx
WM_KEYUP: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=VS.85).aspx
WM_CHAR http://msdn.microsoft.com/en-us/library/windows/desktop/ms646276(v=VS.85).aspx

Article about robus key message handling: http://blog.tavultesoft.com/2008/06/robust-key-mess.html

Example from the manual with keystrokes:

Code:
LRESULT CALLBACK OriginalHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

LRESULT CALLBACK MyMessageHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   if (WM_CHAR == message)
   { 
       printf("Char keystroke");
   }
   else if(WM_KEYDOWN == message) { //...
   }
   //always handle, do not return above
   return OriginalHandler(hwnd,message,wParam,lParam);   	  
}

function main() 
{
   OriginalHandler = on_message;	// store the original message loop
   on_message = MyMessageHandler; // and replace it by your own
   ...
}



If you need any help, just contact me.

Last edited by TechMuc; 10/14/11 07:30.
Re: inchar with more than one character and inchar_active [Re: TechMuc] #385178
10/14/11 07:34
10/14/11 07:34
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
PS: just for yor understanding: When you interfer in the Message Loop, you will not have any problems with multiple keystrokes in one frame anymore, as the MessageHandler will be called IN the engine frame, and allows you to store ANY key stroke, no matter how you like it.

Example:
Code:
Normal behaviour:

//your code
....
...
START_ENGINE_FRAME() (wait(1);
...
... KEYSTROKE
...
...
END_ENGINE_FRAME();
//your code
//you are informed HERE about the keystroke




overloading message loop:

//your code
...
...
START_ENGINE_FRAME()
...
...KEYSTROKE()
//your code in message loop
...
...KEYSTROKE
//your code in message loop
...
END_ENGINE_FRAME()
//your code

you are already defined about the keystroke when your normal lite-c code is resumed after the wait(1) again :)



Re: inchar with more than one character and inchar_active [Re: TechMuc] #385190
10/14/11 14:17
10/14/11 14:17
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline OP

Programmer
Lukas  Offline OP

Programmer

Joined: May 2007
Posts: 2,043
Germany
Thank you TechMuc! This looks exactly like the solution I need! laugh

Page 2 of 2 1 2

Moderated by  aztec, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1