行 21: |
行 21: |
| bool isDown = (state == SButtonState.Pressed || state == SButtonState.Held); | | bool isDown = (state == SButtonState.Pressed || state == SButtonState.Held); |
| </syntaxhighlight> | | </syntaxhighlight> |
− | Available button states:
| + | 可用的按键状态: |
| {| class="wikitable" | | {| class="wikitable" |
| |- | | |- |
行 30: |
行 30: |
| | up | | | up |
| | up | | | up |
− | | <samp>None</samp> | + | | <samp> 无</samp> |
| |- | | |- |
| | up | | | up |
| | down | | | down |
− | | <samp>Pressed</samp> | + | | <samp> 按下</samp> |
| |- | | |- |
| | down | | | down |
| | down | | | down |
− | | <samp>Held</samp> | + | | <samp> 按住</samp> |
| |- | | |- |
| | down | | | down |
| | up | | | up |
− | | <samp>Released</samp> | + | | <samp> 松开</samp> |
| |} | | |} |
| </dd> | | </dd> |
| </dl> | | </dl> |
| {{翻译}} | | {{翻译}} |
− | ===Check cursor position=== | + | === 检查光标位置=== |
− | The <samp>GetCursorPosition()</samp> method provides the [[#ICursorPosition|cursor position in three coordinate systems]].
| + | <samp>GetCursorPosition()</samp> 方法提供了[[#ICursorPosition| 三种坐标体系下的光标位置]] 。 |
| | | |
− | For example:
| + | 例如: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
− | // draw text at the cursor position | + | // 在光标位置绘制文本 |
| ICursorPosition cursorPos = this.Helper.Input.GetCursorPosition(); | | ICursorPosition cursorPos = this.Helper.Input.GetCursorPosition(); |
| Game1.spriteBatch.DrawString(Game1.smallFont, "some text", cursorPos.ScreenPixels, Color.Black); | | Game1.spriteBatch.DrawString(Game1.smallFont, "some text", cursorPos.ScreenPixels, Color.Black); |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | ===Suppress input=== | + | === 抑制输入=== |
− | You can prevent the game from handling any [[#SButton|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.
| + | 你可以通过抑制输入来阻止游戏对[[#SButton| 控制器/ 键盘/ 鼠标]] 的响应。这种抑制会在玩家松开按键前持续生效。这种抑制不会阻止其他mod对输入的处理。 |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
| |- | | |- |
− | ! method | + | ! 方法 |
− | ! effect | + | ! 效果 |
| |- | | |- |
| | <code>Suppress</code> | | | <code>Suppress</code> |
− | | Suppress the specified [[#SButton|<samp>SButton</samp>]] value. | + | | 抑制给定的 [[#SButton|<samp>SButton</samp>]] 值. |
| |- | | |- |
| | <code>SuppressActiveKeybinds</code> | | | <code>SuppressActiveKeybinds</code> |
− | | For the given [[#KeybindList|<samp>KeybindList</samp>]], suppress every button that's part of an activated keybind. | + | | 对于给定的[[#KeybindList|<samp>KeybindList</samp>]] ,抑制其中的每个按键输入。 |
| |- | | |- |
| | <code>IsSuppressed</code> | | | <code>IsSuppressed</code> |
− | | Get whether the specified [[#SButton|<samp>SButton</samp>]] value is currently suppressed. | + | | 检查给定的 [[#SButton|<samp>SButton</samp>]] 值是否正在受到抑制。 |
| |} | | |} |
| | | |
− | For example:
| + | 例如: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
− | // prevent game from seeing that LeftShift is pressed | + | // 使游戏忽略LeftShift按键的动作 |
| this.Helper.Input.Suppress(SButton.LeftShift); | | this.Helper.Input.Suppress(SButton.LeftShift); |
| | | |
− | // that works for clicks too: | + | // 鼠标单击也可以被抑制 |
| 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); | | bool suppressed = this.Helper.Input.IsSuppressed(SButton.LeftShift); |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | Side-effects:
| + | 副作用: |
| <ul> | | <ul> |
| <li>The [[Modding:Modder Guide/APIs/Events#Input.ButtonReleased|<samp>ButtonReleased</samp> event]] will be raised on the next tick for the suppressed input.</li> | | <li>The [[Modding:Modder Guide/APIs/Events#Input.ButtonReleased|<samp>ButtonReleased</samp> event]] will be raised on the next tick for the suppressed input.</li> |