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
40 changes: 40 additions & 0 deletions public/usage-examples/input/key_down-1-example-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using SplashKitSDK;

public class Program
{
static void DrawKeyStatus(string label, KeyCode key, double x, double y)
{
// Check whether the selected key is currently pressed
bool pressed = SplashKit.KeyDown(key);
Color indicator = pressed ? Color.Green : Color.Gray;
string state = pressed ? "Pressed" : "Released";

// Draw the key status indicator and label
SplashKit.FillCircle(indicator, x, y, 25);
SplashKit.DrawText(label + ": " + state, Color.Black, x + 40, y - 10);
}

public static void Main()
{
// Open the window for the usage example
SplashKit.OpenWindow("Keyboard State Display", 800, 400);

while (!SplashKit.WindowCloseRequested("Keyboard State Display"))
{
SplashKit.ProcessEvents();

// Draw the background and instructions
SplashKit.ClearScreen(Color.White);
SplashKit.DrawText("Press the arrow keys or space bar to see their current state.", Color.Black, 120, 40);

// Draw the live status of each selected key
DrawKeyStatus("Left", KeyCode.LeftKey, 120, 130);
DrawKeyStatus("Right", KeyCode.RightKey, 120, 190);
DrawKeyStatus("Up", KeyCode.UpKey, 120, 250);
DrawKeyStatus("Down", KeyCode.DownKey, 120, 310);
DrawKeyStatus("Space", KeyCode.SpaceKey, 500, 220);

SplashKit.RefreshScreen(60);
}
}
}
34 changes: 34 additions & 0 deletions public/usage-examples/input/key_down-1-example-top-level.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using SplashKitSDK;

void DrawKeyStatus(string label, KeyCode key, double x, double y)
{
// Check whether the selected key is currently pressed
bool pressed = SplashKit.KeyDown(key);
Color indicator = pressed ? Color.Green : Color.Gray;
string state = pressed ? "Pressed" : "Released";

// Draw the key status indicator and label
SplashKit.FillCircle(indicator, x, y, 25);
SplashKit.DrawText(label + ": " + state, Color.Black, x + 40, y - 10);
}

// Open the window for the usage example
SplashKit.OpenWindow("Keyboard State Display", 800, 400);

while (!SplashKit.WindowCloseRequested("Keyboard State Display"))
{
SplashKit.ProcessEvents();

// Draw the background and instructions
SplashKit.ClearScreen(Color.White);
SplashKit.DrawText("Press the arrow keys or space bar to see their current state.", Color.Black, 120, 40);

// Draw the live status of each selected key
DrawKeyStatus("Left", KeyCode.LeftKey, 120, 130);
DrawKeyStatus("Right", KeyCode.RightKey, 120, 190);
DrawKeyStatus("Up", KeyCode.UpKey, 120, 250);
DrawKeyStatus("Down", KeyCode.DownKey, 120, 310);
DrawKeyStatus("Space", KeyCode.SpaceKey, 500, 220);

SplashKit.RefreshScreen(60);
}
39 changes: 39 additions & 0 deletions public/usage-examples/input/key_down-1-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "splashkit.h"

void draw_key_status(string label, key_code key, double x, double y)
{
// Check whether the selected key is currently pressed
bool pressed = key_down(key);
color indicator = pressed ? COLOR_GREEN : COLOR_GRAY;
string state = pressed ? "Pressed" : "Released";

// Draw the key status indicator and label
fill_circle(indicator, x, y, 25);
draw_text(label + ": " + state, COLOR_BLACK, x + 40, y - 10);
}

int main()
{
// Open the window for the usage example
open_window("Keyboard State Display", 800, 400);

while (!window_close_requested("Keyboard State Display"))
{
process_events();

// Draw the background and instructions
clear_screen(COLOR_WHITE);
draw_text("Press the arrow keys or space bar to see their current state.", COLOR_BLACK, 120, 40);

// Draw the live status of each selected key
draw_key_status("Left", LEFT_KEY, 120, 130);
draw_key_status("Right", RIGHT_KEY, 120, 190);
draw_key_status("Up", UP_KEY, 120, 250);
draw_key_status("Down", DOWN_KEY, 120, 310);
draw_key_status("Space", SPACE_KEY, 500, 220);

refresh_screen(60);
}

return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions public/usage-examples/input/key_down-1-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from splashkit import *

def draw_key_status(label, key, x, y):
pressed = key_down(key)
indicator = color_green() if pressed else color_gray()
state = "Pressed" if pressed else "Released"

fill_circle(indicator, x, y, 25)
draw_text(label + ": " + state, color_black(), None, 16, x + 40, y - 10)

window = open_window("Keyboard State Display", 800, 400)

while not window_close_requested(window):
process_events()

clear_screen(color_white())

draw_text(
"Press the arrow keys or space bar to see their current state.",
color_black(),
None,
18,
120,
40
)

draw_key_status("Left", KeyCode.left_key, 120, 130)
draw_key_status("Right", KeyCode.right_key, 120, 190)
draw_key_status("Up", KeyCode.up_key, 120, 250)
draw_key_status("Down", KeyCode.down_key, 120, 310)
draw_key_status("Space", KeyCode.space_key, 500, 220)

refresh_screen_with_target_fps(60)

close_window(window)
1 change: 1 addition & 0 deletions public/usage-examples/input/key_down-1-example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keyboard State Display