简体   繁体   中英

Get keyboard event in purescript

I want to get keydown event in purescript so I used DomEvent. Here is my code.

main :: Eff (HA.HalogenEffects (console :: CONSOLE, timer :: T.TIMER)) Unit
main = HA.runHalogenAff do
  body <- HA.awaitBody
  cube <- runUI C.cubes unit body
  documenttarget <- liftEff $ window >>= document <#> DHT.htmlDocumentToEventTarget
  addEventListener (EventType "keydown") (eventListener test) true (documenttarget)

  H.liftEff $ T.setInterval (1000 / frameRate) do
    HA.runHalogenAff $ cube.query $ H.action C.Tick

When I try to run this code, I am getting error like this.

documenttarget <- liftEff $ window >>= document <#> DHT.htmlDocumentToEventTarget
Coudn't match type Eff with type Aff

I know aff and eff but I am new to purescript so I am not sure what I have to do to fix this issue. What can I do?

The block that you pass to halogenRunAff is an Aff block, so every line in it must be an Aff . But liftEff returns an Eff instead. So there is a mismatch.

This is what the compiler is telling you: "can't match Eff with Aff".

To fix this, replace liftEff with liftAff :

documenttarget <- liftAff $ window >>= document <#> DHT.htmlDocumentToEventTarget 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM