Skip to content

Added KeyDown usage example#702

Open
jasveena15 wants to merge 2 commits intothoth-tech:mainfrom
jasveena15:feature/keydown-example
Open

Added KeyDown usage example#702
jasveena15 wants to merge 2 commits intothoth-tech:mainfrom
jasveena15:feature/keydown-example

Conversation

@jasveena15
Copy link
Copy Markdown

Description

This pull request adds a new usage example demonstrating the SplashKit KeyDown function. The example provides a simple and interactive way to understand how real-time keyboard input can be detected and used within a program.

The program opens a window and visually displays the state of specific keys (Space, Left, Right, Up, Down). When a key is pressed, the display updates immediately using visual indicators such as coloured circles and labels.

This contribution is part of improving the SplashKit documentation by adding beginner-friendly, practical examples that help users understand input handling.

No additional dependencies are required beyond the existing SplashKit SDK and project setup.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Documentation (update or new)

How Has This Been Tested?

The example was tested across all supported languages to ensure correctness and consistency.

Python

skm python3 key_down-1-example.py
C#

dotnet run
C++

g++ key_down-1-example.cpp -l SplashKit -o test_program
./test_program

Verification performed:

  • Window opens correctly
  • Key press states update in real time
  • Visual feedback (circles/text) changes correctly when keys are pressed/released
  • No runtime or syntax errors across all implementations
  • All files follow required naming conventions and folder structure

Testing Checklist

  • Tested in latest Chrome
  • Tested in latest Firefox
  • npm run preview

Checklist

If involving code

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Folders and Files Added/Modified

Please list the folders and files added/modified with this pull request and delete options that are not relevant.

  • Added:
  • public/usage-examples/input/key_down-1-example.cpp
  • public/usage-examples/input/key_down-1-example-top-level.cs
  • public/usage-examples/input/key_down-1-example-oop.cs
  • public/usage-examples/input/key_down-1-example.py
  • public/usage-examples/input/key_down-1-example.txt
  • public/usage-examples/input/key_down-1-example.png

Additional Notes

this example was designed to be simple and beginner-friendly, focusing only on demonstrating the KeyDown function without introducing unnecessary complexity. It aligns with the SplashKit usage example style guide and follows the required file structure and naming conventions.

The implementation ensures consistency across C++, C#, and Python versions, making it easier for users to compare and learn across languages.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 21, 2026

Deploy Preview for splashkit failed.

Name Link
🔨 Latest commit 4e7e3d5
🔍 Latest deploy log https://app.netlify.com/projects/splashkit/deploys/69cd12103c78bd00083ab825

Copy link
Copy Markdown

@kottochii kottochii left a comment

Choose a reason for hiding this comment

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

Peer review

Issues found

  • The python example generates warnings due to the script looking for a font that is not necessarily in the user's directory. This may be fixed by not attempting to look for a font and set the respective parameter to None where font may be passed.

Files to test before approval

  • key_down-1-example.py

@jasveena15
Copy link
Copy Markdown
Author

Peer review

Issues found

  • The python example generates warnings due to the script looking for a font that is not necessarily in the user's directory. This may be fixed by not attempting to look for a font and set the respective parameter to None where font may be passed.

Files to test before approval

  • key_down-1-example.py

RESOLVED

Copy link
Copy Markdown

@ralphweng2023 ralphweng2023 left a comment

Choose a reason for hiding this comment

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

The reviewer's feedback has been addressed — the Python draw_text calls now correctly pass None for the font parameter, which resolves the font warning issue. The fix commit (4e7e3d5) targets exactly the right lines. Code across all four language variants (C++, C# top-level, C# OOP, Python) is consistent and follows SplashKit conventions. Approved.

Copy link
Copy Markdown

@kottochii kottochii left a comment

Choose a reason for hiding this comment

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

All files have been tested and perform as required; all examples are shown on the website.

@ekam313
Copy link
Copy Markdown

ekam313 commented Apr 3, 2026

Second Peer Review

I've reviewed the KeyDown usage example again for the second review and checked it against the usage example style guide.

Review Summary

The example is clear, interactive, and demonstrates the KeyDown function effectively. The visual feedback makes it very suitable for beginner users, and the structure is consistent across languages.

However, there are still a few style guide issues that should be addressed before this can be approved.

Required Changes

  1. Loop condition (all languages)
    The examples currently use window_close_requested(...) / WindowCloseRequested(...).
    According to the style guide, usage examples should use:

    • C++: while (!quit_requested())
    • C#: while (!QuitRequested())
    • Python: while not quit_requested()
  2. Ternary operators (all languages)
    The code uses ternary operators (e.g. condition ? value1 : value2).
    The style guide recommends avoiding these for beginner readability.
    Please replace them with simple if/else statements.

  3. C# Top-Level version
    The top-level file is not following the required format:

    • Add: using static SplashKitSDK.SplashKit;
    • Remove SplashKit. prefix and call functions directly (e.g. OpenWindow(...), KeyDown(...))
  4. C# OOP version
    The OOP version is missing a namespace.
    It should follow the format:

    namespace KeyDownExample
    {
        public class Program
        {
            ...
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants