> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# IGameInputDevice::SetLightingColor

> 為輸入裝置上的一或多個燈具暫存一種色彩。

為輸入裝置上的一或多個燈具暫存一種色彩。下次您呼叫 [IGameInputDevice::ApplyLightingColors](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_applylightingcolors.md) 時，此色彩就會傳送至裝置。

## 語法

```cpp theme={null}
void SetLightingColor(
    GameInputColor color,
    GameInputLightingGroups group,
    uint32_t groupOrderIndex = GAMEINPUT_LIGHTING_GROUP_ORDER_INDEX_ALL
);
```

### 參數

*color*\
類型：[GameInputColor](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/structs/gameinputcolor)

要為所選燈具暫存的色彩。

*group*\
類型：[GameInputLightingGroups](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/enums/gameinputlightinggroups)

包含要設定之燈具的燈光群組選取範圍。這可以是一或多個具名群組旗標、用來選取裝置上每個燈具的 `GameInputLightingGroupAll`，或用來選取不屬於任何具名群組之燈具的 `GameInputLightingGroupUnknown`。

*groupOrderIndex*   \_In\_opt\_\
類型：uint32\_t

選取 *group* 內的個別燈具。預設值 `GAMEINPUT_LIGHTING_GROUP_ORDER_INDEX_ALL` 會選取 *group* 中的每個燈具。如需其他值的解譯方式，請參閱「備註」。

### 傳回值

類型：void

## 備註

`SetLightingColor` 不會立即變更燈具。它會為所選燈具記錄 (暫存) 色彩。呼叫 [IGameInputDevice::ApplyLightingColors](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_applylightingcolors.md)，以在單一更新中將所有暫存色彩傳送至裝置。由於在您套用色彩之前不會傳送任何內容，因此您可以設定數個群組或個別燈具，並讓它們同時變更。暫存色彩在套用後仍會持續生效，因此若之後要變更某個群組，您只需要為該群組暫存新色彩並再次套用即可。

*groupOrderIndex* 參數的解譯方式如下。

| *groupOrderIndex* 的值 | 選取的燈具 |
| - | - |
| `GAMEINPUT_LIGHTING_GROUP_ORDER_INDEX_ALL` (0xFFFFFFFF) | *group* 中的每個燈具。 |
| 鍵盤掃描碼 (當 *group* 為 `GameInputLightingGroupKeyboardKey` 時) | 具有該掃描碼之按鍵的燈具。掃描碼使用 Set 1 編碼：0x01 到 0x7F、延伸掃描碼 0xE001 到 0xE07F，或 Pause 鍵的 0xE11D。 |
| 任何其他值 | *group* 內位於該從零開始位置的燈具。此值必須小於 [IGameInputDevice::GetSupportedLightingGroupSize](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getsupportedlightinggroupsize.md) 針對 *group* 傳回的值。 |

將 `GameInputLightingGroupKeyboardKey` 與其他具名群組結合的選取範圍無法選取個別燈具，因為索引會模稜兩可。對於這類選取範圍，請使用 `GAMEINPUT_LIGHTING_GROUP_ORDER_INDEX_ALL`。`GameInputLightingGroupAll` 可以依個別燈具在裝置上所有燈具中之從零開始的位置來選取該燈具。

如果選取範圍對裝置無效，呼叫會被忽略，且不會暫存任何內容。如果選取範圍包含裝置沒有的具名群組 (請參閱 [IGameInputDevice::GetSupportedLightingGroups](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getsupportedlightinggroups.md))、不包含任何燈具，或指定的 *groupOrderIndex* 超出範圍或不是有效的掃描碼，則選取範圍無效。對已中斷連線之裝置的呼叫不會有任何作用。

若要捨棄暫存色彩並讓燈具恢復預設行為，請呼叫 [IGameInputDevice::ApplyLightingSystemDefault](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_applylightingsystemdefault.md)。

下列範例會將控制器的正面按鈕設定為紅色、將其中央燈設定為藍色，然後在單一更新中套用這兩種色彩。

```cpp theme={null}
void SetControllerLighting(IGameInputDevice* device) noexcept
{
    const GameInputLightingGroups groups = device->GetSupportedLightingGroups();

    if ((groups & GameInputLightingGroupFaceButtons) != 0)
    {
        device->SetLightingColor({ 255, 0, 0 }, GameInputLightingGroupFaceButtons);
    }

    if ((groups & GameInputLightingGroupCenterLight) != 0)
    {
        device->SetLightingColor({ 0, 0, 255 }, GameInputLightingGroupCenterLight);
    }

    device->ApplyLightingColors();
}
```

下列範例會調暗具有個別按鍵燈光之鍵盤上的所有按鍵，並醒目提示 A 鍵 (其 Set 1 掃描碼為 0x1E)。

```cpp theme={null}
void HighlightKeyA(IGameInputDevice* device) noexcept
{
    if ((device->GetSupportedLightingGroups() & GameInputLightingGroupKeyboardKey) == 0)
    {
        return;
    }

    device->SetLightingColor({ 16, 16, 16 }, GameInputLightingGroupKeyboardKey);
    device->SetLightingColor({ 0, 255, 0 }, GameInputLightingGroupKeyboardKey, 0x1E);
    device->ApplyLightingColors();
}
```

> [!NOTE]
>
> 燈光支援取決於裝置和平台。目前，GameInput 支援 Windows 動態燈光 (LampArray) 裝置以及 DualSense 控制器燈條上的燈光。

## 需求

**標頭：** GameInput.h

**程式庫：** gameinput.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[GameInput 概觀](https://docs.xbox.com/zh-TW/build/core-features/common/input/overviews/input-overview.md)\
[IGameInputDevice](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/igameinputdevice.md)\
[GameInputColor](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/structs/gameinputcolor)\
[GameInputLightingGroups](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/enums/gameinputlightinggroups)\
[IGameInputDevice::ApplyLightingColors](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_applylightingcolors.md)\
[IGameInputDevice::ApplyLightingSystemDefault](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_applylightingsystemdefault.md)\
[IGameInputDevice::GetSupportedLightingGroups](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getsupportedlightinggroups.md)\
[IGameInputDevice::GetSupportedLightingGroupSize](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getsupportedlightinggroupsize.md)

## 版本歷程記錄

| 版本 | 變更 |
| - | - |
| **v4** | 已推出。 |


## Related topics

- [IGameInputDevice::ApplyLightingColors](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_applylightingcolors.md)
- [IGameInputDevice::ApplyLightingSystemDefault](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_applylightingsystemdefault.md)
- [IGameInputDevice::GetSupportedLightingGroups](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getsupportedlightinggroups.md)
- [IGameInputDevice::GetSupportedLightingGroupSize](https://docs.xbox.com/zh-TW/reference/input/gameinput/interfaces/igameinputdevice/methods/igameinputdevice_getsupportedlightinggroupsize.md)
- [GameInput API 成員](https://docs.xbox.com/zh-TW/reference/input/gameinput/gameinput_members.md)
