keydown event find F-key

I can’t believe I don’t find out how this works. In a KeyDown event, I want to check, whether a certain F-Key is pressed. If I write the following code, I get the messageBox:

if asc(key)=8  then
msgbox("enter")
end

But I cannot find the ASCII value for an F-key. I got “keyF5” and the hex-values, but I can’t find out how to address those. Any ideas are appreciated.

I use an app called Key Codes to help me figure out what I’m looking for. It may or may not be able to help with the F-keys and Xojo.
https://manytricks.com/keycodes/

For a Windows version try https://www.nirsoft.net/utils/keyboard_state_view.html

Look there:
http://documentation.xojo.com/api/hardware/keyboard.html

In a TextArea, the KeyDown Event, I placed that code:

System.DebugLog "Pressed Key: " + Hex(Key.Asc)

and I pressed fn-F1 thru fn-F12 in my MacBook to get their values as hex.

F1 returns F704 (!)
F12 returns F70F

I let you figure the mid values and others for the other keys.

Mac or Windows ?

be aware, that (as far as my testing shows)… there are certain F-keys on macOS that you CANNOT intercept… the OS takes them long before your app ever sees them…

Indeed. That’s why I was asking. The only way therefore becomes to use a timer and to poll the Keyboard class.

Dave, Michel,

you are correct, F11 is not accessible on macOS (El Capitan). All others are ok.

Edit:
this may be useful: fn-F11 hides all applications from all monitors (so you can watch their desktops).

Hey thanks all for the valuable tips! I am working on a mac. So are you saying, the F-keys might have different values on a mac than on a pc?
@Emile Schwarz : your code really helps figuring out the key, thanks. But I sill can find out, how to code the statement to check if my key was pressed. Can anyone direct me here?

You know the key value (as Hex, but use Str and you will get the decimal one) for the depressed key.

What do you need ? A Select Case with all cases ?

[code]Select Case Key

Case “F704”
// It’s F1

Case “F705”
// It’s F2

etc.

Else
// Not a key I am awaiting

End Select[/code]

Is this what you want ?

Run the provided code on a PC and you will get the answer.

FYI… Emile… your code doesn’t work. KEY is a unicode string… NOT “F705” (a text literal), but CHR(&HF705)
so it would be more like

Select case ASC(key)
case &hF705 
etc...

For once, it do not tested.

Thanks for the correct way to do things.

I understand now: I had my code in mind and used impropermy Key instead of my"detecting variable".

Sorry.

Thank you so much Dave and Emile (and the others above)! You made my day.

You should post in the macOS channel, so it makes it easier to address your question. And it also helps other members trying to find the same topic.

Thanks Michel. I’ll do that next time.