Add keyPress.hs

This commit is contained in:
千住柱間 2025-01-31 01:24:37 +00:00
commit 45e54a263e

45
keyPress.hs Normal file
View file

@ -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)