How would we know if "Delete" button on key board is pressed in GWT?
i tried keydown handler ,key press but i cant find methods like "isDeleteKeyDown()".
Thanks
If the keydown event is firing properly for you on press of delete then you can compare the keycode to figure out if the delete key has been pressed. Basically,
if(event.getNativeKeyCode() == KeyCodes.KEY_DELETE)
{ // Delete key pressed, do you stuff }
Related
This question is a follow up from a very old post:
CGEventPost - hold a key (shift)
I am building a SwiftUI virtual keyboard. Like a real keyboard, I have UIButtons that resemble the hardware buttons ( key a, s, d, etc ) which the user can click with their mouse. The user can also toggle to keep a button pressed.
I can send keyDown events using a function below, but an unable to keep a keyboard key held down. Inferring that my users want to hold every button until released, how would I send a CGEvent that would tell the macOS that the key with keyCode == a is being held by the user?
private func pressButton(_ keyCode: UInt16) {
// create a key down event
let eventDown = CGEvent(keyboardEventSource: nil, virtualKey: keyCode, keyDown: true)
// post the key down event
eventDown?.post(tap: .cghidEventTap)
}
I tried intentionally only setting the keyDown event without the keyUp event ( as seen in the above function ), but I get an equivalent of a button press as opposed to hold. I also tried to use timers to fire the pressButton method periodically to keep sending button down events, but ran into the issue of "the events are being sent too fast or too slow", in comparison what would happen if i were to hold that specific button on my keyboard.
A useful thread: Simulate keypress using Swift
I'm fairly new to this.
When I click on the button to rebind the jump key, the rebind works fine. First the panel "Waiting on rebinding..." pops up, then I press the key, I want jump to be, then the new key shows up on the button as the binding.
This works only once though. When I want to click on the same button again, it doesn't allow me to click on it. The button doesn't even change color anymore, when you hover over it.
What I tried to solve this was to duplicate the button. When I click on either of the buttons and rebind the jump key, it works the first time, but not after that. Both buttons are unclickable. Closing and opening the button panel doesn't work either.
Here is the code for the OnClick() on the button:
public void JumpStartRebinding()
{
startRebindObject.SetActive(false);
waitingForInputObject.SetActive(true);
movement.PlayerInput.SwitchCurrentActionMap("UI");
jumpAction.action.Disable();
rebindingOperation = jumpAction.action.PerformInteractiveRebinding()
.WithControlsExcluding("Mouse")
//.WithCancelingThrough("<Keyboard>/escape")
.OnMatchWaitForAnother(0.1f)
.OnComplete(operation => JumpRebindComplete())
.Start();
}
private void JumpRebindComplete()
{
int bindingIndex = jumpAction.action.GetBindingIndexForControl(jumpAction.action.controls[0]);
bindingDisplayNameText.text = InputControlPath.ToHumanReadableString(
jumpAction.action.bindings[bindingIndex].effectivePath,
InputControlPath.HumanReadableStringOptions.OmitDevice);
jumpAction.action.Enable();
rebindingOperation.Dispose();
startRebindObject.SetActive(true);
waitingForInputObject.SetActive(false);
movement.PlayerInput.SwitchCurrentActionMap("Player");
}
The issue doesn't appear to be with your code. I was having this exact same issue a few days ago. It likely has to do with the fact that a UI object is "covering up" the button. A first step I'd take is making sure that nothing is obscuring your button after re-enabling it (often times, TextMeshProUGUI objects with "Raycast Target" enabled are the culprit).
A window/popup in web page can be provided with close (X) button at top-right corner to close that. How to make one closed with 'escape' key pressed?
Facebook chat boxes will be closed with the "esc" key pressed. How to do that?
Thanks.
It's totally depends on which window dialog/popup are you using. Because different dialog/popup can be handled by differently.
But you can use keyboard key press event(key code :27) to detect when use clicked ESC key.
Here is the example:
Suppose, you're using jquery dialog to show your content then you can handle ESC key event.
$(document).keydown(function(e) {
// ESCAPE key pressed
if (e.keyCode == 27) {
window.close();
}
});
Hope this helps!
I want to detect if ctrl is held down when the user clicks a button. The 'clicked' signal doesn't seem to pass enough information to the callback to work this out.
If you can connect to either button-press-event or button-release-event instead of clicked, the event passed to the callback can be used to get the modifier state (using get_state) and check if control key is pressed. For ex.
def button_release_callback(widget, event, data=None):
if event.get_state() & gtk.gdk.CONTROL_MASK:
print "Ctrl held"
else:
print "Ctrl not held"
...
button.connect("button-release-event", button_release_callback)
Hope this helps!
I have a button in a group widget and i simply want to create a keyboard shortcut(enter) so that the button action gets called and focused.Interestingly what happened is when i press space(on keyboard)the respective button action gets called which doesn't work with enter.Eventually all I'm trying to get is simply press enter so that button action triggers.Any ideas so that i can play-around it.
The Enter key (SWT.CR) does not invoke the current button, but rather the default button of the Shell. You set the default button with
shell.setDefaultButton(button);
Maybe what you're searching for is the method #addKeyListener of class Button. Implement a KeyListener and in the #keyReleased(KeyEvent keyEvent) method evaluate keyEvent like this: if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { //your code here}