Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var _caps : bool = false
- func _ready():
- # Godot doesn't have any built in way of checking the status of the caps lock key.
- # This short demonstration will show you a work around.
- # This is an inelegant solution but it seems to work under Windows 10 and Pop_OS! 20.04
- # I would recommend only calling this once when your game starts, after which you can track the changes to the capslock key inside of godot
- # This still needs testing on MacOS, older versions of windows and other linux flavours
- var output = [] # Output will contain the output of the execute function
- if (OS.get_name() == "X11"): # Does this completely fail on Wayland? Maybe it will be better to use a solution similar to windows?
- var err = OS.execute("bash", ["-c", "xset -q | grep Caps"], true, output) # bash calls /bin/bash a command interpreter
- if (err == OK): # xset -q gets the status of the keyboard
- # | grep Caps outputs the line that starts with Caps
- # true pauses the game until the command finishes
- # output, see above
- var result = output[0].split(":")
- if (result[2].find("on") != -1):
- _caps = true
- else:
- print ("Sorry something went wrong. Maybe you don't have bash or xset. Godot Error: " + str(err))
- elif (OS.get_name() == "Windows" or OS.get_name() == "UWP"):
- var err = OS.execute("capsChecker.exe", [], true, output) # This runs a small program written in c++, see capsChecker.cpp
- if (err == OK):
- if (output[0] == "On"):
- _caps = true
- else:
- print ("Sorry something went wrong. Please make sure capsChecker.exe is present in res://. Godot Error: " + str(err))
- elif (OS.get_name() == "MacOS"):
- pass # todo probably need to call a different executive
- else:
- print("You are likely on mobile and the virtual keyboard sorts all this out for you.")
Advertisement
Add Comment
Please, Sign In to add comment