CTRL-I on Windows not working in TextArea

On Windows, I try to add a shortcut when pressing CTRL+i to get italic text. I put this in KeyUp event on a TextArea:

If Keyboard.ControlKey AND Key = "i" Then
  If TARecordContents.SelItalic Then
    TARecordContents.SelItalic = FALSE
  Else
    TARecordContents.SelItalic = TRUE
  End If
End If

But pressing CTRL+i seems to insert a TAB only and erases the selected text.

I verified using no other shortcuts that could interfere.

I found an old thread from the year 2003 that exactly describes my problem: http://www.monkeybreadsoftware.eu/listarchive-realbasic-nug/2003-07-14-4.shtml

But there, a feedback case is mentioned, which I cannot find. And it’s from year 2003 - guess that this should have been fixed in almost fifteen years. :slight_smile:

Can you help? Using an other key than “i” is working, but well… it is standard to use i for italic.

[quote=167586:@Frank Foerster]On Windows, I try to add a shortcut when pressing CTRL+i to get italic text. I put this in KeyUp event on a TextArea:

If Keyboard.ControlKey AND Key = "i" Then
  If TARecordContents.SelItalic Then
    TARecordContents.SelItalic = FALSE
  Else
    TARecordContents.SelItalic = TRUE
  End If
End If

But pressing CTRL+i seems to insert a TAB only and erases the selected text.

I verified using no other shortcuts that could interfere.

I found an old thread from the year 2003 that exactly describes my problem: http://www.monkeybreadsoftware.eu/listarchive-realbasic-nug/2003-07-14-4.shtml

But there, a feedback case is mentioned, which I cannot find. And it’s from year 2003 - guess that this should have been fixed in almost fifteen years. :slight_smile:

Can you help? Using an other key than “i” is working, but well… it is standard to use i for italic.[/quote]

Ctrl-I happens to be chr(9), aka Tab. Could be a bug, or a feature.

The best way to implement functions for control keys is to use a menu item and affect to it I with a key modifier. You could place it in the Edit menu. Then all you do is to add a menu handler to the window that will execute whenever you press Ctrl-I.

To prevent undue call to the handler, you want to enable and disable this menuitem in the TextArea GotFocus and LostFocus. Or remove and add the menuitem itself.

A couple of points…
I agree with Michel that you should use a menu item for setting italic.
But a tab is replacing your text because you failed to Return True from your KeyUp Event.
Secondly, for the future, this block of code…

If TARecordContents.SelItalic Then TARecordContents.SelItalic = FALSE Else TARecordContents.SelItalic = TRUE End If
Can be replaced with one line

TARecordContents.SelItalic = not TARecordContents.SelItalic
If AscB(key)=9 then 
    If (keyboard.CommandKey) or (keyboard.ControlKey) then // covers OSX and Windows
msgbox "Ctrl-I"
else
msgbox "Tab"
end if
end if

[quote=167595:@Michel Bujardet]The best way to implement functions for control keys is to use a menu item and affect to it I with a key modifier. You could place it in the Edit menu. Then all you do is to add a menu handler to the window that will execute whenever you press Ctrl-I.

To prevent undue call to the handler, you want to enable and disable this menuitem in the TextArea GotFocus and LostFocus. Or remove and add the menuitem itself.[/quote]
+1 for this,
-1 the last part. my recommendation is to never remove and add to menus it causes confusion. just disable/enable.

[quote=167695:@Tim Parnell]+1 for this,
-1 the last part. my recommendation is to never remove and add to menus it causes confusion. just disable/enable.[/quote]

I know. We are talking Windows. It is not unusual there.

Actually, even the fact to have Edit menu items for font styles is not evident. WordPad as well as Word have disposed of the edit menu altogether in favor of an awfully crammed toolbar where there are more items than leaves under a tree. The keyboard shortcut appear on a tooltip when the mouse hover the B, I, U style icons.

In OneNote (Modern version of Office), Bold, Italic and Underline appear on a toolbar as well.

The Modern UI (Metro) even does away entirely with drop down menus in favor of panes.
http://designmodo.com/modern-ui/
http://designmodo.com/modern-ui/

To be fair, since the Modern UI is intended to be used with touch only if needed, a drop down menu would not be terribly friendly. Actually, a lot of that interface has similarities with iOS more than the familiar desktop.

It’s just that the user expects to press ctrl+i for italic. So I would consider this as a “big bug” in Xojo.

As soon as I have time this evening I’ll give Dave S’s code snipet a try. I feel that I already did so during my own investigations, but let’s say.

I also found that the CTRL key seems not to be reliable detectable under OS X (10.10.2, Xojo 2015 R1). I haven’t investigated this closer, but noticed that sometimes my keyup/keydown events are not recognizing the ctrl key using the keyboard class.

[quote=168599:@Frank Foerster]It’s just that the user expects to press ctrl+i for italic. So I would consider this as a “big bug” in Xojo.

As soon as I have time this evening I’ll give Dave S’s code snipet a try. I feel that I already did so during my own investigations, but let’s say.

I also found that the CTRL key seems not to be reliable detectable under OS X (10.10.2, Xojo 2015 R1). I haven’t investigated this closer, but noticed that sometimes my keyup/keydown events are not recognizing the ctrl key using the keyboard class.[/quote]

The great philosopher Kant described very well how staying too close prevents one from seeing the perspective. Take a step back, and the whole picture appears.

I just played with a TextArea in Windows, and discovered Ctrl-I actually sets italics automatically.

As the Tab thing, as I said, since Ctrl-I is chr(9), it makes sense the program sees it as such. But all you got to do is to detect when it is a Ctrl-I and not a Tab key.

This in Keydown does the trick very nicely. What you missed is that the key to trap is chr(9).

if key = chr(9) and Keyboard.ControlKey then return true end if

If you still need your TARecordContents.SelItalic property set, simply make it :

TARecordContents.SelItalic = me.selItalic

Bug gone :slight_smile:

@Michel Bujardet : I don’t think that the great Kant knew Xojo… :wink: but Frank Förster says CTRL+i it is not working “out of the box” under Windows.

I gave it a try with an empty text area (multiline, styledtext, accepttabs = enabled). Pressing CTRL+i seems indeed to insert a tab out of the box, but not sets italic text as I need it. Maybe I should say that I also need the ability to add tabs as well.

[quote=168812:@Frank Foerster]@Michel Bujardet : I don’t think that the great Kant knew Xojo… :wink: but Frank Förster says CTRL+i it is not working “out of the box” under Windows.

I gave it a try with an empty text area (multiline, styledtext, accepttabs = enabled). Pressing CTRL+i seems indeed to insert a tab out of the box, but not sets italic text as I need it. Maybe I should say that I also need the ability to add tabs as well.[/quote]

I am sure if Kant had programmed, he would have selected Xojo :wink:

The solution I just posted does not remove the Tab key. It simply prevents Ctrl-I to act as Tab.

Now the Italic thing. I happen to work primarily with Windows 10. Under Windows 10, pressing Ctrl-I sets the TextArea to Italic, Ctrl-B bold, and Ctrl-U underline. Automagically.

I just tested under Windows 8.1, though, and that is not the case. Sorry.

You must therefore use your code to select Italics. I see a potential problem, though, when your software is used in Windows 10. Since Windows 10 sets automatically SelItalic, when it gets to your code, as it stands, it will nullify it. So in effect under Windows 10 you will never get italics. You probably need to set a boolean property like “TARecordContentsOlditalic” in your window at the very end of KeyUp that records the value you selected last in your code. Then instead of looking at TARecordContents.Italic, look at TARecordContentsOldItalic. That way no matter what Windows 10 does automatically, only your code will count.

[code]If TARecordContentsOldItalic Then
TARecordContents.SelItalic = FALSE
Else
TARecordContents.SelItalic = TRUE
End If

OldItalic = TARecordContents.SelItalic
Return[/code]