Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I fire a very specifc KeyPressed event?
    primarykey
    data
    text
    <p>I have the following pseudocode:</p> <pre><code>public void Update() { if (pressed) OnKeyPressed(key); if (held) OnKeyHeld(key); if (released) OnKeyReleased(key) } </code></pre> <p>So that during every Update() if a key is pressed, held, or released than the appropriate event can be raised. This is the actual code for the OnKeyPressed method:</p> <pre><code>public void OnKeyPressed(Keys key) { EventHandler&lt;InputEventArgs&gt; handler = m_keyPressed; if (handler != null) { handler(this, new InputEventArgs(key)); } } </code></pre> <p>However, this isn't really what I want because I don't necessarily care if a key was pressed. What I care about is if a PARTICULAR key is pressed. How can I code this to accomplish this goal without creating an absurd amount of events (one for each key I want to bind)?</p> <hr> <p><strong>RE: Nic-</strong></p> <p>Ok so I combine the classes and here's the resulting pseudo-code:</p> <pre><code>public void OnKeyPressed(Keys key) { if(m_boundKeys.ContainsKey(key)) { //Fire event keyPressed(this, EventArgs.Empty); } } </code></pre> <p>Now, the problem with the above is that the event being fired is still nothing more than an keyPressed event. It's not an A_keyPressed or B_keyPressed event. I can register things to the keyPressed event but that means that every Subscriber recieves a keyPressed event whenever ANY registered key is pressed.</p> <p>I'm looking for:</p> <pre><code>public void OnKeyPressed(Keys key) { if(m_boundKeys.ContainsKey(key)) { //Specific key event based on key } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload