Raised This Month: $51 Target: $400
 12% 

How to get The Key Down And Up Event


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
spider853
Senior Member
Join Date: Jul 2006
Old 06-26-2007 , 08:29   How to get The Key Down And Up Event
Reply With Quote #1

Hi, I Need To Get The +USE and -USE Events... I tried to make something like this
register_clcmd("+use","cl_used",0);
register_clcmd("-use","cl_useu",0);

but it isn't work..

please Help Me
spider853 is offline
Send a message via ICQ to spider853
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 06-26-2007 , 08:31   Re: How to get The Key Down And Up Event
Reply With Quote #2

Fakemeta way:

Code:
static button
button = pev(id,pev_button)
 
if(button & IN_USE)
{
     //do something
}
EDIT:Oh...sorry dunno!
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 06-26-2007 at 08:36.
Alka is offline
spider853
Senior Member
Join Date: Jul 2006
Old 06-26-2007 , 08:35   Re: How to get The Key Down And Up Event
Reply With Quote #3

I know how to check if is a Key but I need to react when a User Press Key "E" and When He Release it


Last edited by spider853; 06-26-2007 at 08:38.
spider853 is offline
Send a message via ICQ to spider853
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-26-2007 , 08:52   Re: How to get The Key Down And Up Event
Reply With Quote #4

It may helps a little : http://forums.alliedmods.net/showthread.php?t=56872

and with :

Quote:
// Attack buttons
UC_Buttons, // unsigned short
__________________
Arkshine is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-26-2007 , 08:56   Re: How to get The Key Down And Up Event
Reply With Quote #5

To check if button is pressed:
Code:
public plugin_init()
{
    register_forward(FM_CmdStart, "fwd_CmdStart");
}

public fwd_CmdStart(id, uc_handle, seed)
{
    new buttons = get_uc(uc_handle, UC_Buttons);
    if(buttons & IN_USE)
    {
        //do something...
    }
}
But i dunno how to check when the key is released.
*edit* Greenberet have the better version..0o *edit*

greetz regalis
__________________

Last edited by regalis; 06-26-2007 at 09:12. Reason: ops
regalis is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 06-26-2007 , 08:58   Re: How to get The Key Down And Up Event
Reply With Quote #6

alka isnt far away.
fakemeta:
Code:
public plugin_init() {     register_forward(FM_PlayerPreThink, "prethink") } public prethink( id ) {      static button,oldbuttons;      button = pev( id, pev_button );      oldbuttons = pev( id, pev_oldbuttons );      if(button & IN_USE && !(oldbuttons & IN_USE))      {            // +use      } else if( oldbuttons & IN_USE && !(button & IN_USE))      {           // -use      } }

@regalis
your version has the problem that +use will allways be executed as long as it got pressed
__________________

Last edited by Greenberet; 06-26-2007 at 09:01.
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 06-26-2007 , 08:59   Re: How to get The Key Down And Up Event
Reply With Quote #7

0o...huh ...you'r right Greenberet!
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
spider853
Senior Member
Join Date: Jul 2006
Old 06-26-2007 , 09:07   Re: How to get The Key Down And Up Event
Reply With Quote #8

BIG THX TO ALL FOR HELP... thx Greenberet

but i how to get rid of that warning message

Warning: Loose indentation on line 15

public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your code here...
register_forward(FM_PlayerPreThink, "prethink",0) //LINE 15 (WARNING)
}
public prethink( id )
{
static button,oldbuttons;
button = pev( id, pev_button );
oldbuttons = pev( id, pev_oldbuttons );
if(button & IN_USE && !(oldbuttons & IN_USE))
{
console_print(id,"USE DOWN");
} else if( oldbuttons & IN_USE && !(button & IN_USE))
{
console_print(id,"USE UP");
}
}
__________________
_____________________________________________
spider853 is offline
Send a message via ICQ to spider853
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-26-2007 , 09:11   Re: How to get The Key Down And Up Event
Reply With Quote #9

You have to indent your code properly.

Code:
public plugin_init() {     register_plugin( PLUGIN, VERSION, AUTHOR );     register_forward( FM_PlayerPreThink, "prethink",0 ); } public prethink( id ) {     static button,oldbuttons;     button = pev( id, pev_button );         oldbuttons = pev( id, pev_oldbuttons );         if( button & IN_USE && !(oldbuttons & IN_USE) )     {         console_print( id,"USE DOWN");     }     else if( oldbuttons & IN_USE && !( button & IN_USE ) )     {         console_print( id, "USE UP" );     } }
__________________
Arkshine is offline
spider853
Senior Member
Join Date: Jul 2006
Old 06-26-2007 , 09:19   Re: How to get The Key Down And Up Event
Reply With Quote #10

Ouch.. Works )) thx
__________________
_____________________________________________
spider853 is offline
Send a message via ICQ to spider853
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode