in my defense: it was a long day and I needed some distraction, so this may be a silly question but here it goes: is it possible to swap keys on entry?
Like in a TextField you press an “a” and a “w” appears instead?
I thought it should be easy, just reassign the key in the KeyDown or KeyApp event but that doesn’t work.
So I’m wondering how key replacement works, and if it is Xojo not making that functionality available, or what the reason for that is.
Any ideas beside mucking around with the TextChanged event?
Or more vicious: in the KeyDown Event, make a copy of the pressed key (as Window Property), then at KeyUp time, make a replace for that key. Easy for only one key, start to be complex for more pressed keys.
Just for completeness sake: the code has to be slightly different as the cursor is otherwise not where you expect it to be if you enter the key inside a text (tested on two Macs & one Windows):
If Key = "a" Then
Dim selStart As Integer = Me.SelStart
Me.SelText = "w"
Me.SelStart = selStart + 1
Return True
End If
Note that you also can’t do
Me.SelStart = Me.SelStart + 1
Not sure what is going on there as it seems somewhat screwy
[quote=441650:@Markus Winter]Just for completeness sake: the code has to be slightly different as the cursor is otherwise not where you expect it to be if you enter the key inside a text (tested on two Macs & one Windows):
If Key = "a" Then
Dim selStart As Integer = Me.SelStart
Me.SelText = "w"
Me.SelStart = selStart + 1
Return True
End If
[/quote]
If Key = "a" Then
Dim selStart As Integer = Me.SelStart
Me.SelText = "w"
Me.SelStart = selStart + 1
Return True
End If
seemed to break on my mac, the caret would vanish and the text field would lose the ability to enter any more characters (other than a) so I added Me.SelLength = 0 which seemed to fix that problem on the mac.
I guess I found a bug and fixed it without you noticing it was an issue
I tried it now on 3 Macs, two with High Sierra, one with Mojave, all with Xojo 2018 R3. Adding SelLength = 0 makes no difference here.
Which System / Xojo combination are you using? As I think there might be a bug in Xojo anyway (those code contortions shouldnt be necessary) it might well manifest in other combinations.
Have you tried restarting? Xojo also tends to become weird when it runs for weeks