TShiftState in MouseDown and MouseUp event handlers lazarus / 31-LCL ---------------------------------------------------------------------- stefanv · 2019-04-03 14:44 I just ran into an interesting problem, which I've already resolved, but I thought I'd share it here in case it bites anyone else. I'm working on an app, one feature of which is that you can introduce labels at runtime, and drag them around over your document (kind of like attaching annotations in a PDF viewer). In my MouseDown event handler, I wanted to check that it was the left button that was pressed, and that no modifier keys were being used, so I wrote: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if (Button = mbLeft) and (Shift = []) then begin ... end At the time I wrote this, I was developing on a Raspberry Pi, connected remotely using TightVNC. The code above didn't work because Shift contained ssLeft. So I changed it to: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if (Button = mbLeft) and (Shift = [ssLeft]) then begin ... end After that, it worked as expected. However, when I went to go test the app on the Raspberry Pi's own local X server, it no longer worked. I discovered that there, Shift was actually an empty set, as I had originally expected it to be. My fix was to rewrite the code like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if (Button = mbLeft) and (Shift * [ssShift,ssCtrl,ssAlt] = []) then begin ... endThis worked properly in both environments. ---------------------------------------------------------------------- Blaazen · 2019-04-03 15:12 Yes, because part of ShiftState is also NumLock (ssNum) and many others, therefore you must always test: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if ssAlt in Shift then ...or what you did Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ... (Shift * [ssShift,ssCtrl,ssAlt] = []) ... Note: there exists handy constant ssModifier defined in unit Controls: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ssModifier = {$if defined(darwin) or defined(macos) or defined(iphonesim)} ssMeta {$else} ssCtrl {$endif};which is ssCtrl everywhere except MacOS. ---------------------------------------------------------------------- stefanv · 2019-04-03 15:17 Thanks Blaazen. I'm curious though, why there's a difference in the presence or absence of ssLeft depending on which X server I am using.