From 9bc6f161d2d8220ed50da9643881e57b04c25e4e Mon Sep 17 00:00:00 2001 From: Matteo Benedetto Date: Tue, 19 Aug 2025 13:29:36 +0200 Subject: [PATCH] Refactor KeyLogger to use a single FontManager instance for rendering text --- key.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/key.py b/key.py index 611e0a9..060c35b 100644 --- a/key.py +++ b/key.py @@ -13,6 +13,7 @@ class KeyLogger: self.window.show() self.running = True self.key_down = True + self.font = sdl2.ext.FontManager("assets/decterm.ttf", size=24) def run(self): # Main loop @@ -34,10 +35,11 @@ class KeyLogger: # Update the window sdl2.ext.fill(self.window.get_surface(), sdl2.ext.Color(0, 0, 0)) + greeting = self.font.render("Press any key...", color=sdl2.ext.Color(255, 255, 255)) + sdl2.SDL_BlitSurface(greeting, None, self.window.get_surface(), None) if hasattr(self, 'message'): - font = sdl2.ext.FontManager("assets/decterm.ttf", size=24) - text_surface = font.render(self.message, color=sdl2.ext.Color(255, 255, 255)) - sdl2.SDL_BlitSurface(text_surface, None, self.window.get_surface(), None) + text_surface = self.font.render(self.message, color=sdl2.ext.Color(255, 255, 255)) + sdl2.SDL_BlitSurface(text_surface, None, self.window.get_surface(), sdl2.SDL_Rect(0, 30, 640, 480)) sdl2.SDL_UpdateWindowSurface(self.window.window) # Refresh the window