From 45e54a263e7f1c615fb3bdc053bd5a23dc02cc4a Mon Sep 17 00:00:00 2001 From: hashirama Date: Fri, 31 Jan 2025 01:24:37 +0000 Subject: [PATCH] Add keyPress.hs --- keyPress.hs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 keyPress.hs diff --git a/keyPress.hs b/keyPress.hs new file mode 100644 index 0000000..333f280 --- /dev/null +++ b/keyPress.hs @@ -0,0 +1,45 @@ +{-# LANGUAGE OverloadedStrings, OverloadedLabels, ImplicitParams #-} + +import Control.Monad (void) +import System.Environment (getArgs, getProgName) +import Data.Text (unpack) +import Data.Int (Int32) +import Data.Maybe +import qualified GI.Gtk as Gtk +import Data.GI.Base +import GI.Gdk as Gdk + +activate :: Gtk.Application -> IO () +activate app = do + + + window <- new Gtk.ApplicationWindow [#application := app, + #title := "Wazajisho"] + + + + controller <- Gtk.new Gtk.EventControllerKey [] + + Gtk.widgetAddController window controller + + + Gtk.on controller #keyPressed $ \_ keyval _ -> do + -- key <- Gdk.keyvalName keyval -- cant use this because the keyname doesnt always match the real key. + {-- + i'll let the keycode displaying while i search for an actual solution for this, but it seems that + it can be a little hard to deal with keycodes: https://superuser.com/questions/1709357/difficulty-remapping-the-super-key + --} + print $ keyval + return True + + + #show window + +main :: IO () +main = do + app <- new Gtk.Application [#applicationId := "wazajisho-test", + On #activate (activate ?self)] + + args <- getArgs + progName <- getProgName + void $ #run app (Just $ progName : args)