Check if fn key pressed on macOS keyboard

Honestly, I am not swearing!

fn + Delete will delete on character to the RIGHT of the cursor (like Control D does) in a TextArea or TextField

In a TextArea, when deleting text, I need to be able to check for something before it deletes the text.

I know how to check for the Delete key, but not for the fn key.

The only reference I’ve found in the documentation is on this page, but it doesn’t;t tell you what the keycode is for the fn button.
http://documentation.xojo.com/api/hardware/keyboard.html#keyboard-keyname

Any Ideas?

You sure know what a KeyCode is (physical location on a Key in a Keyboard) and what a Layout is (a character drawing in the Key).

So, AZERTY and QWERTY ? the A character have two different key codes in these Keyboards.

Yu certainly noticed the KeyCodes list (http://documentation.xojo.com/api/hardware/keyboard.html) and it is uncomplete. So if you do not get your answer here, you can search it using these missing values ($0A, $36-$40 for examples).

Edit:
There are 113 defined KeyCodes in the LR.

The value is 63 (decimal), 3F (Hexa).

To get it, create a new project,
add a PushButton and the code below in Action:

[code] Dim Idx As Integer

For Idx = 32 to 127
LB.AddRow “$” + Hex(Idx)
LB.Cell(LB.LastIndex,1) = Keyboard.keyname(Idx)

If userCancelled Then Exit

Next[/code]

Add a ListBox and name it LB.

Run and laugh.

You can’t test for the Fn key, it’s a special modifier key that doesn’t reach us as Xojo users. You can test for the difference between Delete and Backspace. Apple labels their keyboards delete, but it’s really a backspace.

https://en.wikipedia.org/wiki/Backspace#Computers

Thanks everyone - I got it working.

You have to check if the fn key is pressed in a timer, not in the TextArea KeyDown event.

I added a boolean (“fnPressed”), then checked to see if the fn key was pressed in a timer

fnPressed = if(Keyboard.AsynckeyDown(&h3F), True, False)

in my TextArea I checked if delete or backspace was pressed and if the fnPressed = True

if (Keyboard.AsyncKeyDown(&h33) or Keyboard.AsyncKeyDown(&h75)) and fnPressed then //delete key TextField1.AddText( "Fn + Delete Key Pressed") end if

If someone else needs help with it, here’s an tiny example of checking for fn + delete key being pressed in a TextArea:
http://mark-sweeney.com/XojoExamples/Testfnkey.xojo_binary_project.zip

Glad you found a solution! Limiting research to very briefly for a forum post has misinformed me :slight_smile:

There are downsides to this as the keycode depends on the keyboard layout & language
This is noted on the doc pages http://documentation.xojo.com/api/hardware/keyboard.html