SA-MP Forums Archive
KeyStateChange not registered - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: KeyStateChange not registered (/showthread.php?tid=598984)



KeyStateChange not registered - Marcuse - 19.01.2016

Okay I have a function that toggles the cursor when the Y is pressed
It works well when i want to activate the cursor but when i want to disable it (when SelectTextDraw is active) its not registering any keys on KeyStateChange

PHP Code:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys){
    if(
newkeys KEY_YES){
        if(!
guiActive[playerid]){
            
SelectTextDraw(playerid255);
            
guiActive[playerid] = true;
        } else if(
guiActive[playerid]) {
            
CancelSelectTextDraw(playerid);
            
guiActive[playerid] = false;
        }
    }
    return 
true;




Re: KeyStateChange not registered - Kwarde - 19.01.2016

You might wanna use this: if ((!newkeys & KEY_YES) && (oldkeys & KEY_YES))
It's been a while I been into SAMP, but as far as I know, with your code it works when it's still being pressed, which means it could run many times when you press it (try sending a Client message, when you press the key you could get about 3-5 messages while you press it once), so that's why it might not work (I think - Once again, it's been a while); it's running to many times and could not be processed (I had this once).
And as far as I know, that which I sent checks if you pressed it once, and it will only work if you're not still holding it. Or something like that.


Re: KeyStateChange not registered - Marcuse - 19.01.2016

@Kwarde , I'ts not registering it now at all
f((!newkeys & KEY_YES) && (oldkeys & KEY_YES))


Re: KeyStateChange not registered - Sasquatch - 19.01.2016

You are missing a '!' before the (oldkeys & KEY_YES)


Re: KeyStateChange not registered - Marcuse - 19.01.2016

@Sasquatch , doesn't work either...
Tried with #define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

But again it wont detect any keys when SelectTextDraw is active..


Re: KeyStateChange not registered - Sasquatch - 19.01.2016

Im trying to go over that problem, but it wont detect any keys when SelectTextDraw is active... like you said


Re: KeyStateChange not registered - Vince - 19.01.2016

Selectable textdraw freezes the player much like TogglePlayerControllable does and it is been known that keys are not always registered in that case. I don't think there is a fix. You will have to tell players to press ESC to exit the textdraw selection and/or will have to make a dedicated close button.

Sidenote: don't use too many else-if. Especially in cases where it is not at all necessary. It looks ugly and unprofessional and in general makes code harder to dissect. Either the GUI is active or it is not. There is no "in-between" case.
PHP Code:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys){
    if(
newkeys KEY_YES){
        if(!
guiActive[playerid]) 
        {
            
SelectTextDraw(playerid255);
        } 
        else 
        {
            
CancelSelectTextDraw(playerid);
        }
        
guiActive[playerid] = !guiActive[playerid];
    }
    return 
true;




Re: KeyStateChange not registered - Marcuse - 19.01.2016

Thanks guys for the response!


Re: KeyStateChange not registered - Sasino97 - 29.05.2020

Did anyone find a workaround?
I have the same necessity: the user should be able to press shift to spawn in my skin selection clickable-textdraw-based menu.