Lazarus cross platform equivalent to MapVirtualKey - lazarus

I have been able to successfully retrieve ascii characters from VK codes
using lazarus/fpc and the mapvirtualkey function in windows.
Is there a cross platform (macOS specifically) lazarus/fpc equivalent to mapvirtualkey? Is there any other way to get the ascii/unicode character that corresponds to a VK code under the current keyboard layout using lazarus/fpc on macOS?
Thank you in advance!
Edit: (Rephrased question) The onKeyDown events on Lazarus on a Mac provide a "Key" parameter. Is there a way on the mac to convert this parameter to the ascii/unicode character that corresponds to this "Key"?

I'm kind of confused about what you want also.
But maybe this helps:
Look in the lcltype unit in the lazarus folders, this contains all the "virtual Key" constants (search for vk_ ).
So the "Key" parameter is getting the double value corresponding to VK_RETURN when the Return/Enter key is pressed. And so on with all the extended keyboard characters.
You can use the Ord() and Chr() functions with these values as well which, I believe, will give you want you want (?).
If you are going to use these codes don't forget to add lcltype to your "uses" section.
HTH.

Related

How to create custom escape sequence in mac terminal

I don't understand how to create custom escape sequence for Ctrl+Shift+S like in this question
My problem is that I want to use Ctrl+Shift+S in emacs no-window mode under MacOS terminal. Currently I'm trying to bind this escape sequence to Ctrl+Shift+F12 but I have troubles creating that escape sequence. Maybe there is a batter way to use complex (Ctrl-Shift+anykey) bindings in MacOS terminal with emacs in no-window mode?
You're probably assuming that F12 is a character. It is not. Conventionally, function keys send a sequence of characters.
In Terminal's preferences screen, you can review (most of) the key bindings:
You can also add a key definition (after deciding what characters it ought to send), and associate the Shift and Control modifiers with that key:
For the sake of example, I used the sequence that xterm would send. However, Terminal is not the same as xterm, and you may find other sequences more interesting.
Regarding the related question "What is the correct escape code for control/shift/s": there is no correct escape code because terminals (unless specially configured as illustrated above) do not distinguish between shifted- and unshifted-control characters. To determine what is "correct", you will have to examine your emacs bindings to see what you should send to make it recognize the function you are asking about.

How to use Unicode characters as variable names without extraneous variant selector glyphs?

When I test using emoji as variable names in Swift (XCode 7.2), I have major problems in that only some emoji work. I've determined that it is because some emoji include their base Unicode codepoint followed by a "variation selector".
Is there a way to insert characters into my source code without the unprintable variation selector coming along with the ride and ruining my code?
This mostly seems to be the fault of Apple's implementation of Unicode, where using the character selection pane to insert ♣️ inserts the codepoint for Clubs followed by the variation selector for "use the emoji version, not the plain text style". Inserting ♣ injects both the Clubs codepoint and the "use the text-style" selector.
If not, is there a list of characters to avoid using in variable names? So far, I've found anything involving a card suit to be problematic, as well as any human-like emoji that Apple has enabled for skin tone selection.
You can input individual code points using the "Unicode Hex Input" input source that comes with Mac OS X. See this guide for enabling and using it.
In general, you probably want to avoid non-ASCII identifiers for exactly the reasons you mention. There are many other examples where non-ASCII identifiers can cause problems, and they offer almost no practical benefit.

Fortran library that would enable me to capture arrow key movement

I would like to use arrow keys to move some points in a QuickWin plot in my console applications. Is there a library out there providing support for something like that?
There are quite a few function calls supported by quickwin: try incharqq, getcharqq or peekcharqq. You'll have to write a noddy program to find out what the key sequences for the arrow keys are.
The call that you may be missing is passdirkeysqq with the parameter PASS_DIR_TRUE. This will enable you to see the direction keys. Each one comes out as 2 keys with the lead character being 224.
If you are not getting any success with this, try using the numeric keypad.

Converting NSString to keyCode+modifiers for AXUIElementPostKeyboardEvent

Edit: Turns out, I was misled during my initial explorations of the accessibility APIs. Once I found the secure text field in the AX hierarchy, I was easily able to set the value. Not sure what to do with this question beyond that, but I wanted to update this for future searchers.
I'm working on some code that will post keyboard events to targeted applications using the Accessibility APIs. So far, I have been able to write a trivial app that allows me to type in a string value and then post keyboard events with those key codes to the targeted application. In reality, the strings would be read from another location.
What I have not yet been able to figure out is how to ascertain whether and which modifier keys should also be posted. For instance, when I type Hello, world! into my test application, the input is sent to the other application as hello, world1 because I am not yet including the modifier keys to create the upper case H and the exclamation point. This is made doubly complicated by multi-keystroke characters like é or ü. Sending é sends a raw e with no accent for example.
Is there a simple method I am overlooking for discerning the modifiers to combine with a keycode for creating a particular NSString or unichar? If not, does anyone have a suggestion of how to proceed? So far, the best I have come up with is calling UCKeyTranslate with all possible modifier combinations until I find one that matches the unichar I get using -[NSString characterAtIndex:] I'm not sure this is scalable or reliable, though, given the multi-keystroke nature of some characters as noted above.
Thanks in advance!
This probably won't help. But just in case: Is it really necessary to send keyboard events? Because that is going to get really difficult if you need to support, say, Kotoeri.
It's a simple matter to override insertText: and doCommandBySelector: and send the results of the key sequence, rather than the individual keystrokes.
I have found a example which does the trick but it's incomplete:It will not be a general solution in any case ...how can this handle multiple keyboard layouts ?
There is an cgquartz obsolete function to do so: CGPostKeyboardEvent (not sure it's possible to pass only the char?) may be can still be used (marked undocumented with some side effect to but .. ).
EDIT: UCKeyTranslate as a way to build a dictionary. Interesting but how the OS do this? A better answer should be hidden somewhere !

Portable keycodes in X11?

I want to get mapping-independent key codes, but documentation says that "keycode" in XKeyEvent structure depends on hardware and driver and I can't rely on it. How can I get some portable key codes like VK_* in Windows?
You want key syms, not key codes.
See XKeycodeToKeysym() and /usr/include/X11/keysymdef.h
To be strictly correct (especially with internationalization) you need a whole bunch of code along the lines of http://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c
However, if you're using raw Xlib instead of a toolkit you probably don't care about this kind of thing (if you do you're in for years of work), and XKeycodeToKeysym() is good enough for US keyboards.

Resources