/* * =============== * CL_KeyState * * Returns 0.25 if a key was pressed and released during the frame, * 0.5 if it was pressed and held * 0 if held then released, and * 1.0 if held for the entire time * =============== */ static double CL_KeyState(kbutton_t key) { double val; bool impulsedown, impulseup, down; impulsedown = (key.state & 2) != 0; impulseup = (key.state & 4) != 0; down = (key.state & 1) != 0; val = 0; if (impulsedown && !impulseup) { if (down) { val = 0.5; // pressed and held this frame } else { val = 0; // I_Error (); } } if (impulseup && !impulsedown) { if (down) { val = 0; // I_Error (); } else { val = 0; // released this frame } } if (!impulsedown && !impulseup) { if (down) { val = 1.0; // held the entire frame } else { val = 0; // up the entire frame } } if (impulsedown && impulseup) { if (down) { val = 0.75; // released and re-pressed this frame } else { val = 0.25; // pressed and released this frame } } key.state &= 1; // clear impulses return(val); }
public static float CL_KeyState(ref kbutton_t key) { bool impulsedown = (key.state & 2) != 0; bool impulseup = (key.state & 4) != 0; bool down = key.IsDown;// ->state & 1; float val = 0; if (impulsedown && !impulseup) { if (down) { val = 0.5f; // pressed and held this frame } else { val = 0; // I_Error (); } } if (impulseup && !impulsedown) { if (down) { val = 0; // I_Error (); } else { val = 0; // released this frame } } if (!impulsedown && !impulseup) { if (down) { val = 1.0f; // held the entire frame } else { val = 0; // up the entire frame } } if (impulsedown && impulseup) { if (down) { val = 0.75f; // released and re-pressed this frame } else { val = 0.25f; // pressed and released this frame } } key.state &= 1; // clear impulses return(val); }
public static void KeyUp(ref kbutton_t b) { int k; string c = Cmd_Argv(1); if (!String.IsNullOrEmpty(c)) { k = int.Parse(c); } else { // typed manually at the console, assume for unsticking, so clear all b.down0 = b.down1 = 0; b.state = 4; // impulse up return; } if (b.down0 == k) { b.down0 = 0; } else if (b.down1 == k) { b.down1 = 0; } else { return; // key up without coresponding down (menu pass through) } if (b.down0 != 0 || b.down1 != 0) { return; // some other key is still holding it down } if ((b.state & 1) == 0) { return; // still up (this should not happen) } b.state &= ~1; // now up b.state |= 4; // impulse up }
static void KeyUp(kbutton_t b) { int k; string c; c = cmd.Cmd_Argv(1); if (c.Length > 0) { k = int.Parse(c); } else { // typed manually at the console, assume for unsticking, so clear all b.down[0] = b.down[1] = 0; b.state = 4; // impulse up return; } if (b.down[0] == k) { b.down[0] = 0; } else if (b.down[1] == k) { b.down[1] = 0; } else { return; // key up without coresponding down (menu pass through) } if (b.down[0] != 0 || b.down[1] != 0) { return; // some other key is still holding it down } if ((b.state & 1) == 0) { return; // still up (this should not happen) } b.state &= ~1; // now up b.state |= 4; // impulse up }
static void KeyDown(kbutton_t b) { int k; string c; c = cmd.Cmd_Argv(1); if (c.Length > 0) { k = int.Parse(c); } else { k = -1; // typed manually at the console for continuous down } if (k == b.down[0] || k == b.down[1]) { return; // repeating key } if (b.down[0] == 0) { b.down[0] = k; } else if (b.down[1] == 0) { b.down[1] = k; } else { console.Con_Printf("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) { return; // still down } b.state |= 1 + 2; // down + impulse down }
public static void KeyDown(ref kbutton_t b) { int k; string c = Cmd_Argv(1); if (!String.IsNullOrEmpty(c)) { k = int.Parse(c); } else { k = -1; // typed manually at the console for continuous down } if (k == b.down0 || k == b.down1) { return; // repeating key } if (b.down0 == 0) { b.down0 = k; } else if (b.down1 == 0) { b.down1 = k; } else { Con_Printf("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) { return; // still down } b.state |= 1 + 2; // down + impulse down }
static void KeyUp(kbutton_t b) { int k; string c; c = cmd.Cmd_Argv(1); if (c.Length > 0) k = int.Parse(c); else { // typed manually at the console, assume for unsticking, so clear all b.down[0] = b.down[1] = 0; b.state = 4; // impulse up return; } if (b.down[0] == k) b.down[0] = 0; else if (b.down[1] == k) b.down[1] = 0; else return; // key up without coresponding down (menu pass through) if (b.down[0] != 0 || b.down[1] != 0) return; // some other key is still holding it down if ((b.state & 1) == 0) return; // still up (this should not happen) b.state &= ~1; // now up b.state |= 4; // impulse up }
static void KeyDown(kbutton_t b) { int k; string c; c = cmd.Cmd_Argv(1); if (c.Length > 0) k = int.Parse(c); else k = -1; // typed manually at the console for continuous down if (k == b.down[0] || k == b.down[1]) return; // repeating key if (b.down[0] == 0) b.down[0] = k; else if (b.down[1] == 0) b.down[1] = k; else { console.Con_Printf ("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) return; // still down b.state |= 1 + 2; // down + impulse down }
/* =============== CL_KeyState Returns 0.25 if a key was pressed and released during the frame, 0.5 if it was pressed and held 0 if held then released, and 1.0 if held for the entire time =============== */ static double CL_KeyState(kbutton_t key) { double val; bool impulsedown, impulseup, down; impulsedown = (key.state & 2) != 0; impulseup = (key.state & 4) != 0; down = (key.state & 1) != 0; val = 0; if (impulsedown && !impulseup) if (down) val = 0.5; // pressed and held this frame else val = 0; // I_Error (); if (impulseup && !impulsedown) if (down) val = 0; // I_Error (); else val = 0; // released this frame if (!impulsedown && !impulseup) if (down) val = 1.0; // held the entire frame else val = 0; // up the entire frame if (impulsedown && impulseup) if (down) val = 0.75; // released and re-pressed this frame else val = 0.25; // pressed and released this frame key.state &= 1; // clear impulses return val; }