Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified CppKeyboardColour/CppKeyboardColour.cpp
Binary file not shown.
4 changes: 3 additions & 1 deletion CppKeyboardColour/IKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ class IKeyboard
virtual void PlayAnimation(IAnimation& animation, bool bShouldLoop) = 0;
virtual KeyboardType GetKBType() const = 0;

virtual ~IKeyboard() = default;
virtual bool SetSpeedFactor(float factor) = 0;

virtual ~IKeyboard() = default;
};
71 changes: 44 additions & 27 deletions CppKeyboardColour/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,78 @@
using millisec = std::chrono::milliseconds;

Keyboard::Keyboard(KeyboardType kbType, IKeyboardCommunicatorPtr ptrKbComms)
: m_kbType(kbType),
m_ptrKbComms(std::move(ptrKbComms))
: m_kbType(kbType),
m_ptrKbComms(std::move(ptrKbComms))
{
}

void Keyboard::SetColour(uint8_t r, uint8_t g, uint8_t b, Zone zone)
{
m_ptrKbComms->SetKBColour(zone, m_colourFactory.Create(r, g, b));
m_ptrKbComms->SetKBColour(zone, m_colourFactory.Create(r, g, b));
}

KeyboardType Keyboard::GetKBType() const
{
return m_kbType;
return m_kbType;
};

void Keyboard::SendCode(uint32_t code)
{
m_ptrKbComms->SendKBCode(code);
m_ptrKbComms->SendKBCode(code);
}

void Keyboard::SetBacklightOff()
{
this->SetColour(0x00, 0x00, 0x00, Zone::ALL);
this->SetColour(0x00, 0x00, 0x00, Zone::ALL);
}

void Keyboard::SetBacklightOn()
{
this->SetColour(0x00, 0x00, 0xFF, Zone::ALL);
this->SetColour(0x00, 0x00, 0xFF, Zone::ALL);
}

bool Keyboard::SetSpeedFactor(float factor)
{

@DeviceIoControl DeviceIoControl Jun 10, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some checks to ensure that factor isn't an unreasonably high or unnecessarily low number. (Lets say >= 1% && <= 250%)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a reasonable thing to add. Do you think 250 is a good upper limit? I think there is a limit anyways with how fast it can even switch colour. And I personally think that people would rarely have it play even faster than the animations are right now. For now I think I will add 250 as limit, as you suggested, but it can always be changed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image

Also, when opened from a non-elevated terminal, it will reopen in an elevated separate terminal window. But when an error would happen, it would instantly close. I added a little Press Enter to exit... thing too. It gives users the ability to read the errors in this specific edge case.

image

// Convert percent (1-250) to speed multiplier (0.01 - 2.5)
int percent = static_cast<int>(factor * 100.0f);
if (percent < 1 || percent > 250)
{
std::cout << "Speed value out of range (1-250). Animation will not play.\n";
return false; // reject invalid speed
}

m_speedFactor = factor;
return true;
}

void Keyboard::Animate(IAnimation& animation)
{
for (size_t i = 0; i < animation.Size(); ++i)
{
if (const auto frame = animation.GetFrame(i))
{
m_ptrKbComms->SetKBColour(frame->zone, frame->colour);
std::this_thread::sleep_for(millisec(frame->ms_time));
}
}
// Apply speed factor to the sleep duration
float invSpeed = 1.0f / m_speedFactor;
for (size_t i = 0; i < animation.Size(); ++i)
{
if (const auto frame = animation.GetFrame(i))
{
m_ptrKbComms->SetKBColour(frame->zone, frame->colour);
uint32_t sleepMs = static_cast<uint32_t>(frame->ms_time * invSpeed);
if (sleepMs < 1) sleepMs = 1;
std::this_thread::sleep_for(millisec(sleepMs));
}
}
}

void Keyboard::PlayAnimation(IAnimation& animation, bool bShouldLoop)
{
if (!animation.IsSupportedKB(this->GetKBType()))
{
std::wcout << animation.GetName() << L" animation is not supported on this system.\n";
return;
}

std::wcout << L"Playing " << animation.GetName() << L" animation...\n";
if (!animation.IsSupportedKB(this->GetKBType()))
{
std::wcout << animation.GetName() << L" animation is not supported on this system.\n";
return;
}

do
{
this->Animate(animation);
std::wcout << L"Playing " << animation.GetName() << L" animation...\n";

} while (bShouldLoop);
}
do
{
this->Animate(animation);
} while (bShouldLoop);
}
4 changes: 4 additions & 0 deletions CppKeyboardColour/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ class Keyboard

KeyboardType GetKBType() const;

bool SetSpeedFactor(float factor) override;

~Keyboard() = default;

private:
KeyboardType m_kbType;
ColourFactory m_colourFactory{};
IKeyboardCommunicatorPtr m_ptrKbComms{};

float m_speedFactor = 1.0f;

void Animate(IAnimation& animation);
};
14 changes: 14 additions & 0 deletions CppKeyboardColour/ThemeCommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,18 @@ std::unique_ptr<IAnimation> ProcessThemeCommandLine(const std::vector<std::wstri
std::cout << "Invalid animation name was provided!\n";

return nullptr;
}

float ProcessSpeedCommandLine(const std::vector<std::wstring>& cmdLines)
{
for (size_t i = 0; i < cmdLines.size(); ++i)
{
if (cmdLines[i] == L"-speed" && i + 1 < cmdLines.size())
{
int percent = std::stoi(cmdLines[i + 1]);
if (percent <= 0) percent = 100;
return static_cast<float>(percent) / 100.0f;
}
}
return 1.0f; // normal speed
}
4 changes: 3 additions & 1 deletion CppKeyboardColour/ThemeCommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ enum class BacklightType
ThemeFlags ProcessCmdThemeFlags(const std::vector<std::wstring>& cmdLines);
BacklightType ProcessBacklightCommandLine(const std::vector<std::wstring>& cmdLines);
SystemAnimation ProcessSystemAnimationCommandLine(const std::vector<std::wstring>& cmdLines);
std::unique_ptr<IAnimation> ProcessThemeCommandLine(const std::vector<std::wstring>& cmdLines);
std::unique_ptr<IAnimation> ProcessThemeCommandLine(const std::vector<std::wstring>& cmdLines);

float ProcessSpeedCommandLine(const std::vector<std::wstring>& cmdLines);
Binary file modified CppKeyboardColour/stdafx.cpp
Binary file not shown.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This is a cleaner, more organized, and efficient version of the initial program.
- **Predefined Animated Effects:**
- 🌈 **Fading Colors:** Smooth color transitions (predefined themes).
- 🎥 **Optimized Animations:** Enhanced visual effects using animation objects.
- ⏱️ **Custom Speed:** Change the speed to make an animation faster or slower.

⚠️ **Important Note:** This application requests for **Administrator privileges**. Please ensure you accept the Windows UAC prompt, as Windows Management Instrumentation (WMI) requires this to function correctly.

Expand All @@ -33,7 +34,7 @@ The following commands are supported and can be executed via the **Command Promp
Extract the program zip and run the commands **as an administrator**. To execute the `.exe` files, prepend the `.\` before the command.

```bash
.\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument]
.\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument] -speed [speed]
```
---

Expand Down Expand Up @@ -133,6 +134,25 @@ Extract the program zip and run the commands **as an administrator**. To execute

---

### ⏱️ Custom Speed:

- **Slower**
```bash
.\CLEVO_KeyboardColour.exe theme colourtransform -speed 50
```
🌈 Creates a slow rainbow sweep effect with smooth transitions at 50% speed.

- **Faster**
```bash
.\CLEVO_KeyboardColour.exe theme colourtransform -speed 200
```
🌈 Creates a fast rainbow sweep effect with smooth transitions at 200% speed.


**Setting speed is not required. You can leave it out, and it will default to the standard speed.**

---

## 🛠️ How to Use

1. Download the release which contains the version of the program that supports your system.
Expand All @@ -145,7 +165,7 @@ Extract the program zip and run the commands **as an administrator**. To execute

4. Run the desired command using the syntax:
```
.\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument]
.\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument] -speed [speed]
```

---
Expand Down