module AutoGUI.Keyboard
  ( write
  , typewrite
  , typewriteKeys
  , writeWithInterval
  , press
  , keyDown
  , keyUp
  , hotkey
  )
where

import AutoGUI.Keys
import AutoGUI.Call

import CPython.Simple
import CPython.Simple.Instances
import Data.Text (Text)
import qualified Data.Text as T

-- | Write out some Text as though it were entered with the keyboard
write :: Text -> IO ()
write :: Text -> IO ()
write Text
msg = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"write" [Text -> Arg
forall a. ToPy a => a -> Arg
arg Text
msg] []

-- | Write out some Text as though it were entered with the keyboard, newline is enter
typewrite :: Text -> IO ()
typewrite :: Text -> IO ()
typewrite Text
msg = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"typewrite" [Text -> Arg
forall a. ToPy a => a -> Arg
arg Text
msg] []

-- | Write out some Text as though it were entered with the keyboard, newline is enter
typewriteKeys :: [Key] -> IO ()
typewriteKeys :: [Key] -> IO ()
typewriteKeys [Key]
keys = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"typewrite" ((Key -> Arg) -> [Key] -> [Arg]
forall a b. (a -> b) -> [a] -> [b]
map Key -> Arg
forall a. ToPy a => a -> Arg
arg [Key]
keys) []

-- | Write out some Text as though it were entered with the keyboard, with a specified
--   number of seconds between keypresses
writeWithInterval :: Text -> Double -> IO ()
writeWithInterval :: Text -> Double -> IO ()
writeWithInterval Text
msg Double
interval = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"write" [Text -> Arg
forall a. ToPy a => a -> Arg
arg Text
msg, Double -> Arg
forall a. ToPy a => a -> Arg
arg Double
interval] []

-- | Simulate a keypress
press :: Key -> IO ()
press :: Key -> IO ()
press Key
key = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"press" [Key -> Arg
forall a. ToPy a => a -> Arg
arg Key
key] []

-- | Simulate holding a key down
keyDown :: Key -> IO ()
keyDown :: Key -> IO ()
keyDown Key
key = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"keyDown" [Key -> Arg
forall a. ToPy a => a -> Arg
arg Key
key] []

-- | Simulate releasing a key
keyUp :: Key -> IO ()
keyUp :: Key -> IO ()
keyUp Key
key = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"keyUp" [Key -> Arg
forall a. ToPy a => a -> Arg
arg Key
key] []

-- | Press a key combination
hotkey :: [Key] -> IO ()
hotkey :: [Key] -> IO ()
hotkey [Key]
keys = Text -> [Arg] -> [(Text, Arg)] -> IO ()
forall a. FromPy a => Text -> [Arg] -> [(Text, Arg)] -> IO a
pyautogui Text
"hotkey" ((Key -> Arg) -> [Key] -> [Arg]
forall a b. (a -> b) -> [a] -> [b]
map Key -> Arg
forall a. ToPy a => a -> Arg
arg [Key]
keys) []