示例#1
0
void IN_KeyDown( kbutton_t *b )
{
	bool nokey = ( Cmd_Argc() > 1 );
	int      k = nokey ? -1 : Key_GetKeyNumber(); // -1 if typed manually at the console for continuous down

	if ( k == b->down[ 0 ] || k == b->down[ 1 ] )
	{
		return; // repeating key
	}

	if ( !b->down[ 0 ] )
	{
		b->down[ 0 ] = k;
	}
	else if ( !b->down[ 1 ] )
	{
		b->down[ 1 ] = k;
	}
	else
	{
		Com_DPrintf( "Three keys down for a button!" );
		return;
	}

	if ( b->active )
	{
		return; // still down
	}

	// save timestamp for partial frame summing
	b->downtime = nokey ? 0 : Key_GetKeyTime();

	b->active = true;
	b->wasPressed = true;
}
示例#2
0
/*
============
IN_PrepareKeyUp

For pseudo-button commands which don't need key/time info but do need to be
executed on key-up.
Called by the +command code.
============
*/
void IN_PrepareKeyUp() {
    const char* cmd;
    int key;

    // Get the current key no. If negative, return
    key = Key_GetKeyNumber();

    if (key < 0) {
        return;
    }

    // Get the command & check that it's a +command
    cmd = Cmd_Argv(0);

    if (*cmd != '+') {
        return;
    }

    ++cmd; // skip the '+'

    // Add the command to what's already marked for this command
    if (keyup[key]) {
        char* newcmd = (char*) Z_Malloc(strlen(keyup[key]) + strlen(cmd) + 3);
        sprintf(newcmd, "%s-%s", keyup[key], cmd);
        Z_Free(keyup[key]);
        keyup[key] = newcmd;
    } else {
        keyup[key] = (char*) Z_Malloc(strlen(cmd) + 3);
        sprintf(keyup[key], "-%s", cmd);
    }
}
示例#3
0
void IN_KeyUp( kbutton_t *b )
{
	unsigned uptime;
	bool nokey = ( Cmd_Argc() > 1 );
	int      k = nokey ? -1 : Key_GetKeyNumber(); // -1 if typed manually at the console for continuous down

	if ( k < 0 )
	{
		// typed manually at the console, assume for unsticking, so clear all
		b->down[ 0 ] = b->down[ 1 ] = 0;
		b->active = false;
		return;
	}

	// If this key is marked as down for this button, clear it
	// Also clear sticky state (don't care if there was no key-down)
	if ( b->down[ 0 ] == k || b->down[ 0 ] < 0 )
	{
		b->down[ 0 ] = 0;
	}
	if ( b->down[ 1 ] == k || b->down[ 1 ] < 0 )
	{
		b->down[ 1 ] = 0;
	}

	if ( b->down[ 0 ] || b->down[ 1 ] )
	{
		return; // some other key is still holding it down
	}

	b->active = false;

	// save timestamp for partial frame summing
	uptime = nokey ? 0 : Key_GetKeyTime();

	if ( uptime )
	{
		b->msec += uptime - b->downtime;
	}
	else
	{
		b->msec += frame_msec / 2;
	}

	b->active = false;
}