Skip to content

Instantly share code, notes, and snippets.

@garryspins
Created February 27, 2024 07:59
Show Gist options
  • Save garryspins/058aeae45702475e81a74e250597bb18 to your computer and use it in GitHub Desktop.
Save garryspins/058aeae45702475e81a74e250597bb18 to your computer and use it in GitHub Desktop.
Demon's Souls RPCS3 Shift Support, For Keyboard and Mouse users

Demon's Souls Keyboard/Mouse

This script attempts to rectify a limitation of RPCS3's keypad emulation, the inability to bind to shift+.
If you want base Dark Souls 1/3 kbm controls for Demon's Souls on RPCS3, this is the solution.

Usage

  1. Install the latest version of Python and ensure you have the following packages:

    • pynput
    • pydirectinput
    • ctypes (builtin)
  2. Make the following bind to the corresponding key under the Bindings section

  3. Execute the script (python demonssouls_kbm.py in cmd)

Bindings

Controller Button Keyboard Key
L2 F1
R2 F2
Left Left
Right Right

import pynput
import pydirectinput
from ctypes import windll, create_unicode_buffer, wintypes
class KeyboardListener(pynput.keyboard.Listener):
is_shift_down = False
def __init__(self):
return super().__init__(on_press = self.on_press, on_release = self.on_release)
def can(self):
hwnd = windll.user32.GetForegroundWindow()
length = windll.user32.GetWindowTextLengthW(hwnd)
buf = create_unicode_buffer(length + 1)
windll.user32.GetWindowTextW(hwnd, buf, length + 1)
return "Demon's Souls" in buf.value
def on_press(self, key):
if not self.can(): return
if key == pynput.keyboard.Key.delete: return False
if key == pynput.keyboard.Key.shift_l: self.is_shift_down = True
def on_release(self, key):
if not self.can(): return
if key == pynput.keyboard.Key.shift_l: self.is_shift_down = False
class MouseListener(pynput.mouse.Listener):
def __init__(self, keyboard: KeyboardListener):
self.keyboard = keyboard
return super().__init__(win32_event_filter = self.filter)
def filter(self, message, data):
if not self.keyboard.can(): return
if not self.keyboard.is_shift_down: return
match message:
case self.WM_LBUTTONDOWN:
if self.left(): self.suppress_event()
case self.WM_RBUTTONDOWN:
if self.right(): self.suppress_event()
case self.WM_MOUSEWHEEL:
if self.wheel(wintypes.SHORT(data.mouseData >> 16).value / 120): self.suppress_event()
def left(self):
pydirectinput.press("f2")
return True
def right(self):
pydirectinput.press("f1")
return True
def wheel(self, delta):
pydirectinput.press("left" if (delta < 0) else "right")
return True
kb = KeyboardListener()
mouse = MouseListener(kb)
kb.start()
mouse.start()
import time
while True: time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment