Skip to content

Commit f9377c6

Browse files
authored
Merge pull request adafruit#2885 from jedgarpark/doom_keeb
first commit doom keyboard code
2 parents 5d50d69 + ea006a7 commit f9377c6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

DOOM_Keeb/code.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-FileCopyrightText: 2024 John Park & Tyeth Gundry for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
'''
5+
DOOM launch for Windows
6+
'zdoom.exe' for Windows https://zdoom.org/downloads must be in CIRCUITPY/zdoom directory.
7+
extract https://github.com/fragglet/squashware/releases squashware-1.1.zip, rename to 'doom1.wad',
8+
place in same CIRCUITPY/zdoom directory as the .exe.
9+
'''
10+
11+
import time
12+
import board
13+
from digitalio import DigitalInOut, Direction
14+
import keypad
15+
import neopixel
16+
import usb_hid
17+
from adafruit_hid.keyboard import Keyboard
18+
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
19+
from adafruit_hid.keycode import Keycode
20+
21+
keys = keypad.Keys((board.A1,), value_when_pressed=False, pull=True) # set up NeoKey launch button
22+
23+
kbd = Keyboard(usb_hid.devices) # create keyboard object
24+
layout = KeyboardLayoutUS(kbd)
25+
26+
led = DigitalInOut(board.D13) # on-board LED
27+
led.direction = Direction.OUTPUT
28+
led.value = True
29+
30+
pixel = neopixel.NeoPixel(board.A2, 1, auto_write=False, brightness=1.0) # NeoKey LED
31+
pixel.fill(0x440000)
32+
pixel.show()
33+
34+
def launch_terminal(): # function for launching local DOOM
35+
kbd.send(Keycode.GUI, Keycode.R) # open run cmd
36+
time.sleep(0.25)
37+
# pylint: disable=line-too-long
38+
layout.write("powershell -c \"& { gwmi win32_logicaldisk -f 'DriveType=2' | % { try { $p = $_.DeviceID + 'zdoom\\zdoom.exe'; if (Test-Path $p) { Start-Process $p; break } } catch {} } }\"")
39+
time.sleep(0.25)
40+
kbd.send(Keycode.ENTER)
41+
time.sleep(2)
42+
43+
while True:
44+
event = keys.events.get() # check for keypress
45+
if event:
46+
if event.pressed:
47+
pixel.fill(0xff0000) # brighten LED
48+
pixel.show()
49+
launch_terminal() # launch DOOM
50+
if event.released:
51+
pixel.fill(0x440000) # dim LED
52+
pixel.show()

0 commit comments

Comments
 (0)