ams
May 4, 2025, 12:08pm
1
hello,
i face a strange problem:
while transferring my plugin to skp2025
the ruby-console shows all flags with value 0
for any key hit (notebook and external keyboard).
so nothing works in the plugin.
has anybody any idea, what is causing this?
ruby-console after hitting some keys:
TERRAIN V onKeyDown: key = 16 flags = 0
TERRAIN V onKeyDown: key = 16 flags = 0
TERRAIN V onKeyDown: key = 37 flags = 0
TERRAIN V onKeyDown: key = 40 flags = 0
TERRAIN V onKeyDown: key = 39 flags = 0
TERRAIN V onKeyDown: key = 38 flags = 0
TERRAIN V onKeyDown: key = 91 flags = 0
TERRAIN V onKeyDown: key = 16 flags = 0
TERRAIN V onKeyDown: key = 16 flags = 0
TERRAIN V onKeyDown: key = 17 flags = 0
TERRAIN V onKeyDown: key = 16 flags = 0
TERRAIN V onKeyDown: key = 17 flags = 0
code for output :
puts “bt ****onKeyDown: K:#{key} F:#{flags}”
in older skp-versions on same laptop there are flags shown and everything works well.
thanx in advance for helping
stan
DaveR
May 4, 2025, 12:51pm
2
You haven’t identified the extension.
Did you try installing it fresh from its source instead of copying it from the previous version?
ams
May 4, 2025, 1:33pm
4
hello everybody,
thanx for moving the topic to the right place.
it is my own extension and i put the whole code from the 2023 to the skp 2025 directory, as always.
the extension starts works perfectly,
just besides the detection of flags
in onkeydown.
as wrote, it is the code from api to show key and flags and
it shows always flags 0 .
like
################################################
def onKeyDown(key, repeat, flags, view)
################################################
puts “tools>grid key: #{key} flags: #{flags}”
…
(do ihave to use some special syntax for code snippets here ?)
so i cannot separate the keyboard keys by flags at all
as i can do it in 2018 - 2023.
as said, all skp-installations at the same laptop, so it cannot be the hardware.
so in your skp 2025 installation flags are recognized and shown without problems?
thanx
stan
As far as I know, the flags
have always been broken on MS Windows for Tool#onKeyDown
callbacks.
I just tested in SU17, SU23, SU24 and SU25, … and flags are still broken on MS Windows for Tool#onKeyDown
callbacks.
There are several forum topics here and on SketchUcation about this.
In this one …
The flags parameter to Tool#onKeyDown and Tool#onKeyUp doesn’t make sense
… I posted links to other topics at SCF.
ams
May 4, 2025, 7:48pm
6
hi dan,
thanx a lot for the infos.
in my case flags really worked in older skp-versions,
i could separately identify ctrl and ctrl 2 , for example, and have many diffferent functions connected with them.
i will send you a small video from my previous skp-version soon.
it is unlucky, that they will not really work now. it gave me a lot of functionality.
regards
stan
Just post a code snippet please.
There are several open issues in the bug tracker from years ago:
opened 02:18PM - 02 Oct 20 UTC
bug
Ruby API
SketchUp
logged
In the Tool#onKeyDown and onKeyUp methods, I can't make sense of the flags param… eter. I would expect this parameter to hold the bitflag of the currently pressed modifier keys, just like other tool events, but the bits are wrong.
Knowing all keys pressed in a key down event, not just the most recently pressed, would allow to check for key combinations like Ctrl + Shift, without having to track pressed keys yourself.
```ruby
class FlagsTest
def onKeyDown(key, _repeat, flags, _view)
puts "OnKeyDown"
puts "key: #{key}"
puts "flags: #{flags}"
puts "flags (bin): #{flags.to_s(2)}"
puts "Copy flag: #{flags & COPY_MODIFIER_MASK == COPY_MODIFIER_MASK}"
puts "Constrain flag: #{flags & CONSTRAIN_MODIFIER_MASK == CONSTRAIN_MODIFIER_MASK}"
puts "Alt flag: #{flags & ALT_MODIFIER_MASK == ALT_MODIFIER_MASK}"
puts
# Prevent alt from focusing menu.
key == VK_ALT
end
def onLButtonDown(flags, _x, _y, _view)
puts "onLButtonDown"
puts "flags: #{flags}"
puts "flags (bin): #{flags.to_s(2)}"
puts "Copy flag: #{flags & COPY_MODIFIER_MASK == COPY_MODIFIER_MASK}"
puts "Constrain flag: #{flags & CONSTRAIN_MODIFIER_MASK == CONSTRAIN_MODIFIER_MASK}"
puts "Alt flag: #{flags & ALT_MODIFIER_MASK == ALT_MODIFIER_MASK}"
puts
end
end
Sketchup.active_model.select_tool(FlagsTest.new)
```
Edit: Forum thread: https://forums.sketchup.com/t/the-flags-parameter-to-tool-onkeydown-and-tool-onkeyup-doesnt-make-sense/47273/10
opened 01:26PM - 29 May 20 UTC
bug
Ruby API
SketchUp
logged
On Mac specifically.
When pressing Cmd-Z within a Sketchup::Tool, ``onKeyDown… ``` and ```onKeyUp``` receive the Command key (```VK_COMMAND = 1048576```) but they never get the subsequent alpha key pressed afterwards (say ```Z```). On Windows, this works fine with ```Ctrl```.
That's a little bit annoying because in some plugins I use the 'natural' habit of users to undo / redo with CTRL-Z and CTRL-Y (on Windows) and (Cmd-Z and Cmd-Shift-Z on Mac), even if there is no real creation of geometry (in any case I neutralize the real Undo or Redo).
For instance, when you create a spline curve in BezierSpline or FredoSpline, you do not create immediately geometry, but still it is natural to cancel the last segment, either via Escape or Ctrl-Z.
Maybe this is not possible to do anyway on Mac, because these keys are intercepted at system level.
**Request:**
- it would be good than someone in Sketchup gives some guidance on what should be the best way to handle these situations (instead of each developer inventing its own).
- As a small side-effect, I noticed that when the Undo stack is empty, a Command-Z on Mac would trigger the Zoom function.
opened 06:35PM - 30 Oct 23 UTC
bug
Ruby API
SketchUp
need more info
logged
regression
With SketchUp’s latest releases a problem was introduced that appears to affect … only the PC version of SketchUp. The event onKeyDown, while in a tool, is supposed to fire once each time a user presses a keyboard key. In the following PC release it fires twice:
PC – 23.1.340 64-bit
Mac – 23.1.341 64-bit – Appears to operate properly on the Mac.
I attempted a work-around by using onKeyUp. But then the Alt key only fires with every other use of the Alt key.
Joe…
ams
May 5, 2025, 5:43pm
9
hi dan,
the basis code:
` puts "tools>zf test-rb key: #{key} flags: #{flags}"
zf_test_tool_250505.rb (3.6 KB)
in 2025 i do not get any flag displayed.
in older versions i do.
thanx stan
When I said snippet, I meant a minimum module:
module ZF
# RUN ONCE PER SESSION
unless defined?(@loaded)
submenu = UI.menu("Plugins").add_submenu("ZF-TEST")
submenu.add_item("Test Ruby Tool") {
Sketchup.active_model.select_tool(Testtool.new)
}
@loaded = true
end
class Testtool
def initialize
@cursor_id = 633 # Select cursor
end ###
def onKeyDown(key, repeat, flags, view)
puts "onKeyDown tools>zf test-rb key: #{key} flags: #{flags}"
return true
end ###
def onKeyUp(key, repeat, flags, view)
puts "onKeyUp tools>zf test-rb key: #{key} flags: #{flags}"
return true
end ###
def onSetCursor
UI.set_cursor(@cursor_id)
end ###
end # Testtool class
end # module ZF
Today I tested SU 21 … 25
onKeyDown flags
2021 yes
2022 yes
2023 no
2024 no
2025 no
But even 2021 and 2022 had goofy flags values.
I tried that module on my Mac running 2025 and still get flags. The values require some research to unpack them, but they still work. Suspecting this may have resulted from the conversion of Windows to the Qt library, I tried it on the Labs version that uses Qt on Mac. The flags don’t work there either, which seems to confirm that Qt is responsible.
1 Like
ams
May 6, 2025, 3:36pm
12
hello steve,
thanx for checking.
then it seems a win-problem, in deed.
as dan wrote, it started already with earlier version.
on my win 10 and skp 23, 25 i always get a 0 as flag, for any key combination.
that is unpleasant, since i use many keys in different combinations in my own plugin and have to change things now…unfortunately.
hipefully things get better in the future.
regards
stan
Gesendet von Outlook für Android
I’ve posted an example of using Windows system calls using Ruby’s Fiddle
library: