[IMPLEMENTED] Alternative input (virtual keyboard) for text field

Is it possible to switch the virtual keyboard used for input text in a text field in my URCap?

The keyboard which is used is not good when I want to edit some existing text. It is not possible to move the caret, it always overwrites all existing (which can be annoying, if you have a longer text).
A keyboard which does this better is the one, which is used when changing a feature name.

If not possible, I would place this as a feature request. [EDIT: moved to feature requests]

Btw: in Polyscope are too many different virtual keyboards, this could be made a bit more consistent.

1 Like

The keyboard for the numerical input provides the possibility to set the caret (and also to mark portions to delete/overwrite). I wish this could be possible with the text keyboard.

I’d like to second this request. We have an extension where the user has to enter an expression (text). Not being able to easily edit the expression is a no-go for our customer.

no one else who is annoyed by the current behaviour?
@jbm: any comment from UR? Shouldn’t be too hard to implement (since such a keyboard already exists (edit feature name)). Also, wouldn’t impact current URcaps.

@hch

I reckon I will need a bit more elaboration on the use case for above.
“Annoying” obviously counts, however would make sense to build a bit more around it.

Currently you select the keyboard type in HTML, by either “number” or “text”.
However would it also make sense to toggle e.g. the “Expression Editor”, and what would the use case be?

@jbm Ok, the use case is that the user needs to change the text that he previously typed (e.g. correcting a typo or adjust the value of just one character (e.g. a state number)):

This is an example for sending commands to an external HMI (where the string is quite large (> 20 chars)).

Or, imagine, we have a lot of similar instances (of this URcap), where only a little portion of the text differs, so the user uses copy-paste and wants to change the new ones a little bit.
In the current situation, he needs to type it every time all over again.

If you were the user and I (as the provider of this URcap) tell you, that you cannot correct/change portions of the text, but instead you have to remember the (complete) previous text and type it all over again, how would you deal with this?

Try to change only one character of a feature name, that’s easily doable, right? -> Polyscope already has such a keyboard (and a change wouldn’t impact existing URcaps).

Please no advice, how to implement this in another way in the URcap (e.g. reducing the text), since this is just a constructed example, it’s all about editing existing / previously entered text.

@artiminds or anyone else, do you have further (detailed) arguments?

1 Like

Thanks, @hch
This use-case is great, I will move on with a feature request in this respect.

There are spots within the current Polyscope where we have the same issue, I believe for instance popups and the user assignment screen where once you have entered the text that you want the user to see you cannot edit it (with the built-in keyboard, have to use an external keyboard). Annoying is not even the right word for it., especially when you cannot even see all of what you typed on the same screen and you now have to retype all of it to fix a single typo.

2 Likes

request implemented in PolyScope 3.4

3 Likes

I have been looking for a tutorial or example on how to implement the numerical keyboard, as i am pretty new to UR.
any suggestions ?

https://plus.universal-robots.com/urcap-basics/api-reference-docs/

Quick link to the API guide.

In your Contribution’s constructor, it can be helpful to assign an instance of the UserInteraction interface like so:

userInteraction = apiProvider.getUserInterfaceAPI().getUserInteraction();

Here’s an example of the code used in the Contribution to create an Integer keyboard, complete with a Validator that will restrict user input to be between whatever is passed as the minValue and maxValue.

public KeyboardNumberInput<Integer> getIntegerKeyoard(Integer initialValue, Integer minValue, Integer maxValue) {
		KeyboardInputFactory keyboardFactory = userInteraction.getKeyboardInputFactory();
		InputValidationFactory validationFactory = userInteraction.getInputValidationFactory();
		
		InputValidator<Integer> validator = validationFactory.createIntegerRangeValidator(minValue, maxValue);
		
		final KeyboardNumberInput<Integer> keyboardInput = keyboardFactory.createIntegerKeypadInput();
		keyboardInput.setErrorValidator(validator);
		keyboardInput.setInitialValue(initialValue);
		
		return keyboardInput;
	}

This example is written to take 3 arguments: a value that will appear by default in the field when clicked (almost always just pulling the .getText() of the object) , a minimum value, and a maximum value.

This is called from the View by putting the following inside whatever onClick listener you’ve chosen:

final KeyboardNumberInput<Integer> keyboardInput = provider.get().getIntegerKeyoard(
	    Integer.valueOf(myTextField.getText()), 
	    (int)minValue, 
	    (int)maxValue);
	keyboardInput.show(myTextField, provider.get().getCallbackForMyTextField());

Then finally you also need to include a Callback method in your contribution that overrides the “on ok” method so you can capture the user pressing the OK button:

	@Override
	public KeyboardInputCallback<Integer> getCallbackForMyTextField() {
		return new KeyboardInputCallback<Integer>() {

			@Override
			public void onOk(final Integer value) {
				onMyTextFieldValueChanged(value);
			}
		};
	}

Then you can do whatever you want to do in the “onMyTextFieldValueChanged()” method. You could also just put it in the onOK method if you wanted, but I like to break things up for clarity. Typically this is where you’d do some model.set() calls to store whatever the user has typed to the model.