Home Image-Pro General Discussions

KeyDown Event in IP Premier

I would like to utilize a KeyDown event in Premier to toggle the Segmentation overlay on and off.
I thought I would be able to use the following Sub declaration. However I am receiving an "Expecting Var Name" error.
If I comment out the Handles declaration at least it loads but the event is not handled it seems.
 
The question is what is the best way to build an event handler for KeyDown or KeyPress events in Premier. It appears that MyBase and MyClass are not supported.
 
Also, it would be great to hook the event to the Threshold dialog so only events related to this dialog would need to be handled.
 

Private Sub Ovl_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

Best Answers

  • Answer ✓
    OK, I understand what you are after. It can be done using the KeyUp event of the image workspace area. In the code below, you just have to call Initialize to enable this behavior.

    Public Module Module1
    
        Private WithEvents _windows As McWindows
    
        Public Sub Initialize()
            _windows = ThisApplication.Windows
        End Sub
    
        Private Sub _windows_KeyUp(ByVal Window As MediaCy.IQL.Application.Interop.IMcWindow, ByVal lKeyCode As Integer, ByVal lShift As Integer, ByRef bHandled As Boolean) Handles _windows.KeyUp
            If lKeyCode = system.Windows.Forms.Keys.Space Then
                ToggleThresholdOverlay
            End If
        End Sub
    
        Public Sub ToggleThresholdOverlay
            Dim dlg As MediaCy.Addins.ThresholdTool.ThresholdTool=ThisApplication.Panels.Control("ThresholdTool")
            If dlg IsNot Nothing Then
                'read data from dialog
                With MediaCy.Addins.ThresholdTool.ThresholdToolOptions.FromObject(dlg)
                    'toggle overlay
                    .ShowOverlay =Not .ShowOverlay
                    .Execute()
                End With
            End If
        End Sub
    
    End Module
    
  • edited August 2013 Answer ✓
    Hi Rod,

    You can do all of this easier, as Pierre suggested in the beginning, just use a macro with a shortcut like this:
        Public Function Toggle() As SimpleScript
            Toggle = New SimpleScript
            Toggle.Shortcut = MediaCy.IQL.Application.mcScriptShortcut.F12
            Call ToggleThresholdOverlay
        End Function
    
    This macro will be called and toggle the threshold overlay when user presses F12 regardless of what control is active and you don't have to click on the image. 

    Yuri

  • Answer ✓
    mcScriptShortcut includes a lot of key combinations, you can see it in the intellisence of the enum or in the properties window of the designer. Space bar is not available, you can use almost all Ctrl, Alt and Shift key combinations and functional keys.
    The documentation is not complete yet, but will be improved in 9.1 version, we are working on it.

Answers

  • The easiest way to do that would be to associate a shortcut to the macro doing the toggle. There's no code needed for that, just record the macro and set the shortcut in the project workbench.

    Pierre
  • What I was planning to do was allow the user to toggle the state of the Threshold overlay using the space bar. The Premier code to turn on and off the overlay is not the problem.

    I would like to use the VB.NET keydown or keypress event and then test for the space key. It would be great to hook this event directly to the Threshold dialog. This would minimize the need to test for the system state at keypress meaning at keypress or down, only active when the Threshold dialog is onscreen. I am trying to minimize mouse interaction. 

  • Thank you for the code. This works to be sure. However, one must click the image in order to enable the toggle. What I was hoping to do was to hook the threshold dialog.

    For clarity, the process places an ROI on the image and then enables the threshold dialog so that the operator can adjust the threshold. In as much the threshold dialog has focus and not the image frame. The toggle is hooked to the image frame and will not trigger until the focus is transferred to the image frame. Is it possible to hook both the image and dialog frames so to speak?

    Also, could you basically clarify KeyUp event

     

    Private Sub _windows_KeyUp(

         ByVal Window As MediaCy.IQL.Application.Interop.IMcWindow, (Do not understand.  Can you clarify what this is doing and where is the variable "Window" used?)

         ByVal lKeyCode As Integer, (I understand)

         ByVal lShift As Integer, (I Understand)

         ByRef bHandled As Boolean) (I understand)

         Handles _windows.KeyUp  (I understand

     

    Also, if the Threshold dialog is already displayed, is the following basically used as a "already on screen" flag so as not to try to toggle as there is nothing to toggle? Dimensioning another Threshold dialog does not create a duplicate it would appear? This suggests that if the dialog is already displayed, this results in a pointer to the existing dialog, not a new one, correct?

    1. Dim dlg As MediaCy.Addins.ThresholdTool.ThresholdTool=ThisApplication.Panels.Control("ThresholdTool")
    2. If dlg IsNot Nothing Then
  • Thanks Yuri:

    To be sure not nearly as complex. Does mcScriptShortcut include the space bar or all keys for that matter?

    I must say, IQL is very impressive and I have not even scratched the surface. However, the docs need to be expanded to help navigation along with a narrative. It is easy to get lost in the help docs.

    Keep up the good work, Premier is a terrific tool.

Sign In or Register to comment.