Changes

→‎Suppress input: clarify how suppression affects events and other input methods
Line 117: Line 117:  
You can prevent the game from handling any controller/keyboard/mouse button press (including clicks) by ''suppressing'' it. This suppression will remain in effect until the player releases the button. This won't prevent other mods from handling it.
 
You can prevent the game from handling any controller/keyboard/mouse button press (including clicks) by ''suppressing'' it. This suppression will remain in effect until the player releases the button. This won't prevent other mods from handling it.
   −
For example, this will prevent the game from seeing that the <tt>LeftShift</tt> button is pressed:
+
For example:
 
<source lang="c#">
 
<source lang="c#">
 +
// prevent game from seeing that LeftShift is pressed
 
this.Helper.Input.Suppress(SButton.LeftShift);
 
this.Helper.Input.Suppress(SButton.LeftShift);
</source>
     −
That works for clicks too:
+
// that works for clicks too:
<source lang="c#">
   
this.Helper.Input.Suppress(SButton.MouseLeft);
 
this.Helper.Input.Suppress(SButton.MouseLeft);
 +
 +
// check if a button is being suppressed:
 +
bool suppressed = this.Helper.Input.IsSuppressed(SButton.LeftShift);
 
</source>
 
</source>
   −
You can also check if a button is being suppressed:
+
Side-effects:
 +
<ul>
 +
<li>The [[Modding:Modder Guide/APIs/Events#Input.ButtonReleased|<tt>ButtonReleased</tt> event]] will be raised on the next tick for the suppressed input.</li>
 +
<li>Methods like <tt>helper.Input.IsDown(button)</tt> and <tt>helper.Input.GetState(button)</tt> will show the button as released for the duration of the suppression, even if it's physically still pressed. You can use <tt>helper.Input.IsSuppressed(button)</tt> to check if that's the case (it will only be true until the button is physically released):
 
<source lang="c#">
 
<source lang="c#">
if (this.Helper.Input.IsSuppressed(SButton.LeftShift))
+
bool isPhysicallyDown = helper.Input.IsDown(button) || helper.Input.IsSuppressed(button);
  // left shift button is being suppressed
+
</source></li>
</source>
+
</ul>
    
==See also==
 
==See also==
 
* [[../Events#Input|Input events]]
 
* [[../Events#Input|Input events]]
 
* [[Modding:Player Guide/Key Bindings]] for a list of valid <tt>SButton</tt> values
 
* [[Modding:Player Guide/Key Bindings]] for a list of valid <tt>SButton</tt> values
translators
8,404

edits