Browse Source

lovr.system.wasKeyPressed/Released;

bjorn 1 year ago
parent
commit
68c90f97d2

+ 71 - 3
api/init.lua

@@ -355,6 +355,7 @@ return {
       key = "lovr.keypressed",
       key = "lovr.keypressed",
       module = "lovr",
       module = "lovr",
       related = {
       related = {
+        "lovr.system.wasKeyPressed",
         "lovr.keyreleased",
         "lovr.keyreleased",
         "lovr.textinput",
         "lovr.textinput",
         "lovr.system.isKeyDown"
         "lovr.system.isKeyDown"
@@ -390,6 +391,7 @@ return {
       key = "lovr.keyreleased",
       key = "lovr.keyreleased",
       module = "lovr",
       module = "lovr",
       related = {
       related = {
+        "lovr.system.wasKeyReleased",
         "lovr.keypressed",
         "lovr.keypressed",
         "lovr.textinput",
         "lovr.textinput",
         "lovr.system.isKeyDown"
         "lovr.system.isKeyDown"
@@ -35421,6 +35423,8 @@ return {
           key = "lovr.system.isKeyDown",
           key = "lovr.system.isKeyDown",
           module = "lovr.system",
           module = "lovr.system",
           related = {
           related = {
+            "lovr.system.wasKeyPressed",
+            "lovr.system.wasKeyReleased",
             "lovr.keypressed",
             "lovr.keypressed",
             "lovr.keyreleased"
             "lovr.keyreleased"
           },
           },
@@ -35428,16 +35432,16 @@ return {
             {
             {
               arguments = {
               arguments = {
                 {
                 {
-                  name = "key",
+                  name = "...",
                   type = "KeyCode",
                   type = "KeyCode",
-                  description = "The key."
+                  description = "The set of keys to check."
                 }
                 }
               },
               },
               returns = {
               returns = {
                 {
                 {
                   name = "down",
                   name = "down",
                   type = "boolean",
                   type = "boolean",
-                  description = "Whether the key is currently pressed."
+                  description = "Whether any of the keys are currently pressed."
                 }
                 }
               }
               }
             }
             }
@@ -35576,6 +35580,70 @@ return {
               returns = {}
               returns = {}
             }
             }
           }
           }
+        },
+        {
+          name = "wasKeyPressed",
+          summary = "Check if a key was pressed this frame.",
+          description = "Returns whether a key on the keyboard was pressed this frame.",
+          key = "lovr.system.wasKeyPressed",
+          module = "lovr.system",
+          notes = "Technically this returns whether the key was pressed between the last 2 calls to `lovr.system.pollEvents`, but that function is called automatically at the beginning of each frame in `lovr.run`, so it all works out!",
+          related = {
+            "lovr.system.isKeyDown",
+            "lovr.system.wasKeyReleased",
+            "lovr.keypressed",
+            "lovr.keyreleased"
+          },
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "...",
+                  type = "KeyCode",
+                  description = "The set of keys to check."
+                }
+              },
+              returns = {
+                {
+                  name = "pressed",
+                  type = "boolean",
+                  description = "Whether any of the specified keys were pressed this frame."
+                }
+              }
+            }
+          }
+        },
+        {
+          name = "wasKeyReleased",
+          summary = "Check if a key was released this frame.",
+          description = "Returns whether a key on the keyboard was released this frame.",
+          key = "lovr.system.wasKeyReleased",
+          module = "lovr.system",
+          notes = "Technically this returns whether the key was released between the last 2 calls to `lovr.system.pollEvents`, but that function is called automatically at the beginning of each frame in `lovr.run`, so it all works out!",
+          related = {
+            "lovr.system.isKeyDown",
+            "lovr.system.wasKeyPressed",
+            "lovr.keypressed",
+            "lovr.keyreleased"
+          },
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "...",
+                  type = "KeyCode",
+                  description = "The set of keys to check."
+                }
+              },
+              returns = {
+                {
+                  name = "released",
+                  type = "boolean",
+                  description = "Whether any of the specified keys were released this frame."
+                }
+              }
+            }
+          }
         }
         }
       },
       },
       objects = {}
       objects = {}

+ 1 - 0
api/lovr/callbacks/keypressed.lua

@@ -21,6 +21,7 @@ return {
   },
   },
   returns = {},
   returns = {},
   related = {
   related = {
+    'lovr.system.wasKeyPressed',
     'lovr.keyreleased',
     'lovr.keyreleased',
     'lovr.textinput',
     'lovr.textinput',
     'lovr.system.isKeyDown'
     'lovr.system.isKeyDown'

+ 1 - 0
api/lovr/callbacks/keyreleased.lua

@@ -16,6 +16,7 @@ return {
   },
   },
   returns = {},
   returns = {},
   related = {
   related = {
+    'lovr.system.wasKeyReleased',
     'lovr.keypressed',
     'lovr.keypressed',
     'lovr.textinput',
     'lovr.textinput',
     'lovr.system.isKeyDown'
     'lovr.system.isKeyDown'

+ 6 - 4
api/lovr/system/isKeyDown.lua

@@ -2,24 +2,26 @@ return {
   summary = 'Get the state of a key.',
   summary = 'Get the state of a key.',
   description = 'Returns whether a key on the keyboard is pressed.',
   description = 'Returns whether a key on the keyboard is pressed.',
   arguments = {
   arguments = {
-    key = {
+    ['...'] = {
       type = 'KeyCode',
       type = 'KeyCode',
-      description = 'The key.'
+      description = 'The set of keys to check.'
     }
     }
   },
   },
   returns = {
   returns = {
     down = {
     down = {
       type = 'boolean',
       type = 'boolean',
-      description = 'Whether the key is currently pressed.'
+      description = 'Whether any of the keys are currently pressed.'
     }
     }
   },
   },
   variants = {
   variants = {
     {
     {
-      arguments = { 'key' },
+      arguments = { '...' },
       returns = { 'down' }
       returns = { 'down' }
     }
     }
   },
   },
   related = {
   related = {
+    'lovr.system.wasKeyPressed',
+    'lovr.system.wasKeyReleased',
     'lovr.keypressed',
     'lovr.keypressed',
     'lovr.keyreleased'
     'lovr.keyreleased'
   }
   }

+ 33 - 0
api/lovr/system/wasKeyPressed.lua

@@ -0,0 +1,33 @@
+return {
+  summary = 'Check if a key was pressed this frame.',
+  description = 'Returns whether a key on the keyboard was pressed this frame.',
+  arguments = {
+    ['...'] = {
+      type = 'KeyCode',
+      description = 'The set of keys to check.'
+    }
+  },
+  returns = {
+    pressed = {
+      type = 'boolean',
+      description = 'Whether any of the specified keys were pressed this frame.'
+    }
+  },
+  variants = {
+    {
+      arguments = { '...' },
+      returns = { 'pressed' }
+    }
+  },
+  notes = [[
+    Technically this returns whether the key was pressed between the last 2 calls to
+    `lovr.system.pollEvents`, but that function is called automatically at the beginning of
+    each frame in `lovr.run`, so it all works out!
+  ]],
+  related = {
+    'lovr.system.isKeyDown',
+    'lovr.system.wasKeyReleased',
+    'lovr.keypressed',
+    'lovr.keyreleased'
+  }
+}

+ 33 - 0
api/lovr/system/wasKeyReleased.lua

@@ -0,0 +1,33 @@
+return {
+  summary = 'Check if a key was released this frame.',
+  description = 'Returns whether a key on the keyboard was released this frame.',
+  arguments = {
+    ['...'] = {
+      type = 'KeyCode',
+      description = 'The set of keys to check.'
+    }
+  },
+  returns = {
+    released = {
+      type = 'boolean',
+      description = 'Whether any of the specified keys were released this frame.'
+    }
+  },
+  variants = {
+    {
+      arguments = { '...' },
+      returns = { 'released' }
+    }
+  },
+  notes = [[
+    Technically this returns whether the key was released between the last 2 calls to
+    `lovr.system.pollEvents`, but that function is called automatically at the beginning of
+    each frame in `lovr.run`, so it all works out!
+  ]],
+  related = {
+    'lovr.system.isKeyDown',
+    'lovr.system.wasKeyPressed',
+    'lovr.keypressed',
+    'lovr.keyreleased'
+  }
+}