Trying to get codename1 textfields to activate when a newline is
entered, the best I've done is to define this in a textfield
subclass
public void keyPressed(int keycode)
{
if(keycode==-90) // where does this number come from?
{ fireDoneEvent();
}
}
Where does this mysterious constant "-90" come from.
Is there a better supported way to do this?
Key pressed will only be invoked in a physical keyboard and not on virtual keyboard so you are in a completely wrong direction. If this is a multiline text field you can easily recognize the newline with \n using the DataChangeListener if this is a single line text field you should use the done listener which will only work on the device (with the VKB).
Related
Simple question I hope - I have a pdf and want to detect the co-ordinates of specific word(s) or placeholder text. I then intend to use itextsharp to stamp a replacement bit of text on top at the co-ordinates found.
Can anyone recommend anything please?
Thanks
As answered in the comments, one could use iText to perform such a task. Maybe there are some better solutions, however, I doubt it. The cause of the mentioned issue, i.e. "[itextsharp] sometimes give co-ords of the start of the sentence the search text is in", is that sometimes glyphs are so close, that their boxes overlap, hence I don't see how it could be handled as you want.
So you can do the following:
extend LocationTextExtractionStrategy class and override eventOccurred, for example, as follows:
#Override
public void eventOccurred(IEventData data, EventType type) {
if (type.equals(EventType.RENDER_TEXT)) {
TextRenderInfo renderInfo = (TextRenderInfo) data;
// Obtain all the necesary information from renderInfo, for example
LineSegment segment = renderInfo.getBaseline();
// ...
}
pass an instance of such an extended class to PdfTextExtractor.getTextFromPage as follows:
PdfTextExtractor.getTextFromPage(pdfDocument.getPage(1), new ExtendedLocationTextExtractionStrategy()
once text is found, the event will be triggered.
There are some difficulties in such a solution, of course, because the text you want to find and write above could be present in the PDF not as "Text", but "T", "ex", t", or even "t", "x", "e", "T". However, since you use iText, you may want to harness the advantages of one of its products - pdfSweep. This product aims to completely remove unnecessary content from the PDF, with such a content being passed either as some locations (which you want to obtain, so that is not an option) or regexes.
This is how to create such a regex strategy (to find all "Dolor" and "dolor" instances in the document, completely remove them (from all the streams, so that they are either not observed from a PDF viewer nor found in the underlying PDF objects):
RegexBasedCleanupStrategy strategy = new RegexBasedCleanupStrategy("(D|d)olor").setRedactionColor(ColorConstants.GREEN);
This is how to use it:
PdfAutoSweep autoSweep = new PdfAutoSweep(strategy);
autoSweep.cleanUp(pdf); // a PdfDocument instance
And this is how to write some text on the location, at which the unnecessary text was present:
for (IPdfTextLocation location : strategy.getResultantLocations()) {
Rectangle rect = location.getRectangle();
// do something, for exapmle, write some text
}
I'm using vuetify components in my current project and now I am facing a problem:
how to prevent the user from entering characters other than letters and numbers?
I do not mean form validating I'd prefer not to alow to eter restricted symbols at all.
Should I create a directive or something like that?
You can put something like this as the onKeyPress event handler:
(event) => {
if (!event.key.match(/[0-9a-zA-Z]/g)) {
event.preventDefault();
}
}
This will prevent key-presses outside the alphanumeric range from being entered. However, note that this is not foolproof (e.g. it will still allow you to copy-paste symbols into the field), so you might still want some sort of validation.
I like to assign what I consider the most useful/used shortcut in my IDE or editor to the 0 on the numeric keypad. I find it fast and convenient. I have keypad in NumLock mode but that is fine. I would like to assign Sublime's SH-CTRL-P to this key but I can't seem to do it. I can get close with the PLUS key by using:
{ "keys": ["keypad_plus"], "command": "show_overlay", "args": {"overlay": "command_palette"} }
I've tried keypad_zero and keypad_0 but neither worked. Can it be done? What's the magic string?
keypad0 should work. Found by logging input sublime.log_input(True) though I think there is a list somewhere too, just to lazy to find it. :)
I'm trying to automate keyboard typing with UI Automation.
target.frontMostApp().keyboard().typeString("INTERCOM")
But i will get this error after first 'I' is typed
target.frontMostApp().keyboard() failed to locate key 'N'
Script threw an uncaught JavaScript error: target.frontMostApp().keyboard() failed to locate key 'N'
I have a localized swedish keyboard.
Anyone know if this a bug or something I've missed?
This might help:
var vKeyboard = target.frontMostApp().keyboard();
vKeyboard.setInterKeyDelay(0.1);
vKeyboard.typeString("INTERCOM");
By default this delay is set with 0.03 seconds. This is not enough for your application to update the keys on your keyboard. Increasing this timeout between determining keys for typeString keyboard method will help you. There is no description for setInterKeyDelay on UIAKeyboard reference page but this method is available for UIAKeyboard.
Also I'm not sure about other languages. I do not know if typeString allows to type on other languages but this 100% works for English keyboard for iOS 5.x.
try{
target.delay(1);
target.frontMostApp().mainWindow().textFields()[0].tap();
target.delay(1);
target.frontMostApp().mainWindow().textFields()[0].setValue("INTERCOM");
}
catch(err){
target.delay(1);
target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].tap();
target.delay(1);
target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].setValue("INTERCOM");
}
I've had this problem as well and I believe it's a case of the string being typed too quickly.
It seems that the names of the key,change depending on the status of the shift button.If shift is enabled then the key is called 'N',if shift is not enabled then it's 'n'.You'll notice as a string is being typed,that the shift button is tapped before an uppercase letter is typed.Your test is attempting to press the 'N' key before the 'Shift' button has been pressed.It doesn't affect the first letter of your sentence because the keyboard has shift enabled for the first letter.
This also affects typing a lowercase character after an uppercase character:the lowercase character may be typed whilst the shift button is in the process of being unpressed.
I use a workaround of typing each letter of the string with separate typeString() methods.
for (i = 0; i < title.length; i++)
{
var strChar = title.charAt(i);
target.frontMostApp().keyboard().typeString(strChar);
}
The downside to this is that it takes a lot longer to type the full string.
You may also want to look at the following link which provides a similar solution but uses the app.keyboard().keys().tap() method for each character of the string instead of the typeString() method.
http://jojitsoriano.wordpress.com/2011/06/27/ios-ui-automation-typing-a-string-in-a-uiatextfield/
I am working on a small RTE in a contentEditable DIV. I have attached a keypress event handler to the DIV that monitors when the ENTER key is struck and where the selection is. If it is inside a text node, I am inserting a new line. However, this code is buggy and often inserts 4 newlines instead of one (I have to press undo 4 times to get back to where the cursor was before - that's why I think execCommand is firing multiple times). On the other hand, it sometimes requires TWO strikes of the ENTER key to get a new line inserted.
here is a code snippet of the keypress event handler, once it's determined that the ENTER key has been pressed:
if(selection.focusNode.nodeType!=3){ return; }
ev.preventDefault();
var HTML='
';
toolbar.target.ownerDocument.execCommand('insertHTML',false,HTML);
I want to use execCommand to preserve the browser's undo behavior. I do NOT want to insert a <br> as this insertion only happens in a text node and for post-processing purposes, I need \n in the text nodes instead of <br>'s or any other block-type tags. I am using the unicode newline character
. I have tried the carriage return character
as well with similar results. I can't use \n with insertHTML because that is not proper HTML.
Anyone have ideas about how to make sure that execCommand runs ONLY once?