problem: edit something captured from clipboard before user pastes it into app.
if you copy multiline text for pasting into a single line textfield, the CRLF or CR or LF chars are essentially ignored when the user pastes the text. in theory, this is ok, except the last word on one
line is joined together with the first word on the next line, creating a single, potentially nonsensical word. (the app parses what it sees in the textfield). if i could replace instances of CRLF or CR or LF with a space - thus separating 2 words - that would be ideal for my purposes. (yes, i could use a multiline textfield, but that introduces a different set of issues.)
i'm using the jNativeHookB4j library, jNativeHook.jar and the KeyComboListener class for the application.
so, intercepting ctrl + "v" (paste) doesn't work as expected since it's triggered after the combination is pressed. (i was looking for it to kick in before the os sees it. after is too late.) so i switched tactics
and captured when the user has pressed ctrl + "c" (copy). i thought i would scan the captured clipboard text to see if there were any instances of CRLF, CR or LF, and - if so - replace them with a space.
i would then returned the new text to the clipboard (fx.setString()). when the user pressed ctrl + "v" to paste, i would simply let nature takes its course.
while i am able to capture the text in the clipboard and, apparently, put a modified version back (no error triggered), the text which was originally in the clipboard still appears in the textfield when the user pastes.
here is the code:
(as mentioned, capturing the key presses and fx.Clipboard.GetString work as expected)
<code>
Sub kcl_KeyComboPressed ' ie, ctrl + "c"
' Log(kcl.GetKeyComboStringRepresentation & " pressed.")
If fx.Clipboard.HasString Then
Dim gotString As String = fx.Clipboard.GetString
' Log("got:" & gotString)
gotString = "my new text would go here" ' RegexReplaceAll("[\r\n]", gotString, "")
fx.Clipboard.SetString( gotString )
Else
Log("nothing for you at this time")
End If
End Sub
</code>
what am i missing?
if you copy multiline text for pasting into a single line textfield, the CRLF or CR or LF chars are essentially ignored when the user pastes the text. in theory, this is ok, except the last word on one
line is joined together with the first word on the next line, creating a single, potentially nonsensical word. (the app parses what it sees in the textfield). if i could replace instances of CRLF or CR or LF with a space - thus separating 2 words - that would be ideal for my purposes. (yes, i could use a multiline textfield, but that introduces a different set of issues.)
i'm using the jNativeHookB4j library, jNativeHook.jar and the KeyComboListener class for the application.
so, intercepting ctrl + "v" (paste) doesn't work as expected since it's triggered after the combination is pressed. (i was looking for it to kick in before the os sees it. after is too late.) so i switched tactics
and captured when the user has pressed ctrl + "c" (copy). i thought i would scan the captured clipboard text to see if there were any instances of CRLF, CR or LF, and - if so - replace them with a space.
i would then returned the new text to the clipboard (fx.setString()). when the user pressed ctrl + "v" to paste, i would simply let nature takes its course.
while i am able to capture the text in the clipboard and, apparently, put a modified version back (no error triggered), the text which was originally in the clipboard still appears in the textfield when the user pastes.
here is the code:
(as mentioned, capturing the key presses and fx.Clipboard.GetString work as expected)
<code>
Sub kcl_KeyComboPressed ' ie, ctrl + "c"
' Log(kcl.GetKeyComboStringRepresentation & " pressed.")
If fx.Clipboard.HasString Then
Dim gotString As String = fx.Clipboard.GetString
' Log("got:" & gotString)
gotString = "my new text would go here" ' RegexReplaceAll("[\r\n]", gotString, "")
fx.Clipboard.SetString( gotString )
Else
Log("nothing for you at this time")
End If
End Sub
</code>
what am i missing?