From: Jonas Rebmann <jre@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Jonas Rebmann <jre@pengutronix.de>
Subject: [PATCH 1/2] input: add input_is_key_pressed() to read single key
Date: Thu, 07 May 2026 13:10:39 +0200 [thread overview]
Message-ID: <20260507-input_is_key_pressed-v1-1-fc701980cb37@pengutronix.de> (raw)
In-Reply-To: <20260507-input_is_key_pressed-v1-0-fc701980cb37@pengutronix.de>
input_key_get_status() while being powerful and able to read all key
states at once, is difficult to use correctly, as the single incorrect
usage in upstream code shows.
Reading multiple key states at once, for any meaningful number of keys
combined (typically up to three) provides no advantage over checking the
keys sequentially.
Provide a simple input_is_key_pressed() function that checks a single
keycode.
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
drivers/input/input.c | 14 ++++++++++++++
include/input/input.h | 1 +
2 files changed, 15 insertions(+)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index e5509bf90d..ea3f4ef255 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -84,6 +84,20 @@ void input_key_get_status(unsigned long *keys, int bits)
bitmap_or(keys, keys, idev->keys, bits);
}
+bool input_is_key_pressed(int key)
+{
+ struct input_device *idev;
+ bool pressed = false;
+
+ if (key > KEY_MAX)
+ return false;
+
+ list_for_each_entry(idev, &input_devices, list)
+ pressed = pressed || test_bit(key, idev->keys);
+
+ return pressed;
+}
+
struct input_console {
struct console_device console;
struct input_notifier notifier;
diff --git a/include/input/input.h b/include/input/input.h
index 9445d20e56..3e03eb9a65 100644
--- a/include/input/input.h
+++ b/include/input/input.h
@@ -24,6 +24,7 @@ int input_device_register(struct input_device *);
void input_device_unregister(struct input_device *);
void input_key_get_status(unsigned long *keys, int bits);
+bool input_is_key_pressed(int key);
struct input_notifier {
void (*notify)(struct input_notifier *in, struct input_event *event);
--
2.53.0.610.g30c4861dc6
next prev parent reply other threads:[~2026-05-07 11:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 11:10 [PATCH 0/2] input: Supersede input_key_get_status() with input_is_key_pressed() Jonas Rebmann
2026-05-07 11:10 ` Jonas Rebmann [this message]
2026-05-07 11:10 ` [PATCH 2/2] ARM: boards: protonic-imx6: use input_is_key_pressed() Jonas Rebmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260507-input_is_key_pressed-v1-1-fc701980cb37@pengutronix.de \
--to=jre@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox