Skip to content

Add feature #11942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
escfoe2 opened this issue Jan 20, 2024 · 1 comment
Closed

Add feature #11942

escfoe2 opened this issue Jan 20, 2024 · 1 comment
Assignees
Labels
feature request A request to make an enhancement (not a bug fix) Library: Other Arduino libraries that don't have their own label Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug

Comments

@escfoe2
Copy link

escfoe2 commented Jan 20, 2024

Adding public method and small change to Keypad.h

bool isPressed(char keyChar, bool bypassStateChange = false);
bool isHolding(char keyChar);
bool wasPressed(char keyChar);

Adding methods to Keypad.cpp

/// @brief Check if a particular key is pressed
/// @param keyChar The key you want to check
/// @param bypassStateChange Disregard the state check, useful if you want to continuously know if this key is being held down without waiting for the HOLD state to be met.
/// @return True if the key has been pressed and the state has been changed, unless the state has been bypassed, then simply True as long as the key is pressed.
bool Keypad::isPressed(char keyChar, bool bypassStateChange = false) {
	for (byte i=0; i<LIST_MAX; i++) {
		if ( key[i].kchar == keyChar ) {
			if ( (key[i].kstate == PRESSED) && (key[i].stateChanged || bypassStateChange) )
				return true;
		}
	}
	return false;	// Not pressed.
}
/// @brief Check if a particular key was pressed and reset its state so that doesn't repeat until pressed again.
/// @param keyChar The key you want to check
/// @return True if the key has been pressed and False until it has been released and pressed again
bool Keypad::wasPressed(char keyChar) {
	for (byte i=0; i<LIST_MAX; i++) {
		if ( key[i].kchar == keyChar ) {
			if ( (key[i].kstate == PRESSED) && key[i].stateChanged ){
				key[i].stateChanged = false;
				return true;
			}				
		}
	}
	return false;	// Not pressed.
}
/// @brief Check if a particular key is being help
/// @param keyChar The key you want to check
/// @return True if the key is being held down
bool Keypad::isHolding(char keyChar) {
	for (byte i=0; i<LIST_MAX; i++) {
		if ( key[i].kchar == keyChar ) {
			if ( (key[i].kstate == KeyState::HOLD))
				return true;
		}
	}
	return false;	// Not pressed.
}

Just useful for quickly and easily determining that a specific key has been pressed and/or held. With or without state.

Purpose:
I'm using the keypad to also double as a directional pad to act as WASD input.

@per1234 per1234 self-assigned this Jan 20, 2024
@per1234 per1234 added feature request A request to make an enhancement (not a bug fix) Library: Other Arduino libraries that don't have their own label labels Jan 20, 2024
@per1234
Copy link
Collaborator

per1234 commented Jan 20, 2024

Hi @escfoe2. "Keypad" is a 3rd party library not maintained by Arduino, so this feature request is off topic for this issue tracker. You can submit it to the repository of the "Keypad" library if you like.

@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 20, 2024
@per1234 per1234 added the Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug label Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A request to make an enhancement (not a bug fix) Library: Other Arduino libraries that don't have their own label Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug
Projects
None yet
Development

No branches or pull requests

2 participants