Detect Ctrl outside a Tool
-
Strange!
I get an "unknown" error when loading Getkeys.rb.
Difficult to tell more, as whether by opening Sketchup or loading the file via the Ruby console, the error is desperatly "unknown".Otherwise, I would suggest that the community of Ruby developers tries to come up with a uniform solution to complement some missing functiosn of the Ruby API. If this DL programs works both on Windows and Mac, then it is really a good base. We could package it as a library, and a few of us in charge of updating it.
Then, we could develop a few other functions that could be useful and probably require to go down to the System:
- Move the mouse cursor to a given position
- Intercept keys before Sketchup (when in a tool, all the short cuts like Space, 'L', etc..., are actually trapped by Sketchup, before they even reach the tool OnKeyDown method
- Access to the main loop in order to be able to interrupt a lengthy process by typing a key
Fredo
-
Here is some Mac code to read the keyboard. It was written by Kevin Willey and he gave me permission to post it here. I don't have a Mac so I can't test it.
Although Ruby/DL works on Windows and Mac this ruby code will only work on Mac.#Ruby code that will get the keyboard State on Mac. #Written by Kevin Wiley #requires RubyDL to load the GetKeys.dylib require 'sketchup.rb' require "dl" require "dl/import" module GetKeys extend DL;;Importable dlload(Sketchup.find_support_file("GetKeys.dylib","plugins/")) extern "BOOL TestForKeyDown(short)" def GetKeys.getKeyState(key) puts(key) if GetKeys.testForKeyDown(key) then puts(key.to_s + "key is down") return(true) else puts(key.to_s + "key is not down") return(false) end end end #USAGE #GetKeys.getKeyState(0x03B) whenever you want to check for control key and #GetKeys.getKeyState(0x038) whenever you want to check for shift
It uses Ruby/DL to load the Mac dylib (attached). Ruby/DL (http://ttsky.net/ruby/ruby-dl.html) does the same thing as Win32api.so. And it rocks. Not only is it cross platform but it is much easier to use and more powerful. It even allows a ruby function to be used a as a C callback.
I have packaged up the Windows and Mac 0SX Ruby/DL and attached it. The .so file is Win and the .bundle file is Mac. Place it in the plugins/ folder.
-
I have them all, and in the right place as specified in the Zip file.
I hope you find the issue, so that we can educate the approach. -
@unknownuser said:
Strange!
I get an "unknown" error when loading Getkeys.rb.
Difficult to tell more, as whether by opening Sketchup or loading the file via the Ruby console, the error is desperatly "unknown".Otherwise, I would suggest that the community of Ruby developers tries to come up with a uniform solution to complement some missing functiosn of the Ruby API. If this DL programs works both on Windows and Mac, then it is really a good base. We could package it as a library, and a few of us in charge of updating it.
Then, we could develop a few other functions that could be useful and probably require to go down to the System:
- Move the mouse cursor to a given position
- Intercept keys before Sketchup (when in a tool, all the short cuts like Space, 'L', etc..., are actually trapped by Sketchup, before they even reach the tool OnKeyDown method
- Access to the main loop in order to be able to interrupt a lengthy process by typing a key
Fredo
First you are trying this on a Mac right? I wasn't clear in the orginial post that this code only Works on Mac because I dont have a windows version of GetKeys.dylib.
If you are running Mac that "Unknown" error happens when something goes wrong loading the either the DL.Bundle or the GetKeys.dylib. Make sure you have it like this.
plugins/getkeys.rb
plugins/getkeys.dylib
plugins/dl.bundle
plugins/dl/import.rb
etc.I am sure Ruby/DL does work on both Mac and windows. I may not have packaged up the Ruby/dl quite right. The zip file I received had also had a "DL" file that was 0 bytes long.
I think the idea of creating a cross platform library is awesome! I would definitely contribute.
-
@unknownuser said:
I have them all, and in the right place as specified in the Zip file.
I hope you find the issue, so that we can educate the approach.Are you trying it on Mac or Windows?
-
I am running Windows XP on a regular laptop.
I am still running Sketchup 6.0.515, in case this does matter. -
I would like to help out on this. I have both a Mac and a Windows machine and am set up for development on both, but I can't focus on this until after 3DBC.
-
@unknownuser said:
I am running Windows XP on a regular laptop.
I am still running Sketchup 6.0.515, in case this does matter.Ah. That is probably the problem. I didn't make it clear in my original post that this code is Mac only because I dont have a Win version of GetKeys.dylib. Use the first code I posted on Windows.
-
@unknownuser said:
I would like to help out on this. I have both a Mac and a Windows machine and am set up for development on both, but I can't focus on this until after 3DBC.
Can you test the GetKeys code I posted on Mac? I want to make sure it works.
-
Too bad, as I thought we had a method to provide a utility libraries based on operating system, but portable between PC and Mac.
I guess this is possible, but we just need to package to offer the same interface, even with different code and binaries underneathThanks anyway for this contribution. I'll try to have a closer look whenever I have some time left.
Advertisement