KeyStateChange not registered
#1

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;

Reply
#2

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.
Reply
#3

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

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

@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..
Reply
#6

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

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;

Reply
#8

Thanks guys for the response!
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)