<p>Hi Nicolas,</p>
<p>I'm following the discussion on the background. I think you're right on using the keycode and not an ascii code. Using ascii to identify keys is a vestige from old "silly terminals". However, there are no keys in ascii to identify for example keys like ctrl, cmd or alt by themselves (and not as modifiers).</p>
<p>Regarding keyboard events (dunno about mousewheel in particular), my take here is that existing windowing/ui frameworks (cocoa/carbon, x11, windows forms..) send two different kind of events:</p>
<ul>
<li>key up / key down => identify wether a key is pressed or released with key code, no text is available. Here we can catch single ctrl/alt/cmd/F[X]/etc presses.</li>
<li>a text event (which we call key press ourselves, maybe misleading) which sends text in some encoding as soon as it is available + associated modifiers</li>
</ul>
<p>Now, the complication here to me is that historically morphic (in squeak and pharo, probably cuis still too?) has been using the text event to drive everything, even shortcuts. So the code managing keyup/downs is not used at all in my experience, and the code managing keypresses in morphs is overly complicated. And changing this while changing the VM at the same time can lead easily to a state where we cannot type :).</p>
<p>Now, as a single small step in what I believe is the right direction, I've implemented in Pharo mappings of keyboard virtual tables => the VM sends the raw virtual keycode to the image side (which depends on the platform) and on the image side this platform dependent virtual keycode is mapped to a common representation for all of them. Like that a single virtual key code table is used in client code. When I did that a couple of years ago, I've chosen to use "in image" X11's virtual key codes because it looked the broader and it seemed to contain the ones from osx and windows. Check <a href="https://github.com/pharo-project/pharo/blob/Pharo8.0/src/System-Platforms/KeyboardKey.class.st">https://github.com/pharo-project/pharo/blob/Pharo8.0/src/System-Platforms/KeyboardKey.class.st</a>.</p>
<p>Then the idea is that morphic events are extended to get the correct key object with a double dispatch:</p>
<div class="highlight highlight-source-smalltalk"><pre><span class="pl-c1">KeyboardEvent</span> <span class="pl-k">>></span> key
        <span class="pl-k">^</span><span class="pl-k">Smalltalk</span> os <span class="pl-c1">keyForValue:</span> keyValue

<span class="pl-c1">UnixPlatform</span> <span class="pl-k">>></span> <span class="pl-c1">keyForValue:</span> aKeyValue
        <span class="pl-k">^</span><span class="pl-c1">KeyboardKey</span> <span class="pl-c1">valueForUnixPlatform:</span> aKeyValue.</pre></div>
<p>Still missing, some accessors for common keys like <code>KeyboardKey f11</code> <code>KeyboardKey ctrl</code>, which would allow for code like the following to open/close a morph while a key is being pressed (without an active wait ;)).</p>
<div class="highlight highlight-source-smalltalk"><pre><span class="pl-c1">MyMorph</span><span class="pl-k">>></span><span class="pl-c1">keyDown:</span> anEvent
        anEvent key <span class="pl-k">=</span> <span class="pl-c1">KeyboardKey</span> alt
             <span class="pl-k">ifTrue:</span> [ <span class="pl-k">self</span> openWindowSelector ]

<span class="pl-c1">MyMorph</span><span class="pl-k">>></span><span class="pl-c1">keyUp:</span> anEvent
        anEvent key <span class="pl-k">=</span> <span class="pl-c1">KeyboardKey</span> alt
             <span class="pl-k">ifTrue:</span> [ <span class="pl-k">self</span> closeWindowSelector ]</pre></div>
<p>A similar approach could be implemented vm side to map events. I like however the image one because it can be changed easily :)</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/456?email_source=notifications&email_token=AIJPEWYAACVBAI5B5MBA6CDQ2SBTJA5CNFSM4J3Y2YXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHVMHTQ#issuecomment-569033678">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AIJPEW4UYQL2YD4UWP4RGOTQ2SBTJANCNFSM4J3Y2YXA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AIJPEW7OROSIMCBWELW3DHTQ2SBTJA5CNFSM4J3Y2YXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHVMHTQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/456?email_source=notifications\u0026email_token=AIJPEWYAACVBAI5B5MBA6CDQ2SBTJA5CNFSM4J3Y2YXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHVMHTQ#issuecomment-569033678",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/456?email_source=notifications\u0026email_token=AIJPEWYAACVBAI5B5MBA6CDQ2SBTJA5CNFSM4J3Y2YXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHVMHTQ#issuecomment-569033678",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>