OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-08-2010, 08:45
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 146
Default What key called macro

good day
a have a macro, which has invoke by 2 keys (Q and W) from Corel Draw X3. I am bind macro with this keys. Does anyone know how to define WHAT exactly (key "Q" or key "W" or mouse event) has called macro ? May be last key in keyboard buffer or last event or something else.
Reply With Quote
  #2  
Old 02-08-2010, 10:32
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Hi.

I'm not sure.
I know the API GetKeyState() can get a current key state.

There should be other ways to go about finding out.

If you set W and Q to run different Subs that each perform it's needed function is the usual way to go.

-John
Reply With Quote
  #3  
Old 03-08-2010, 05:55
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 146
Default

Thank you for answer
Whether exists a possibility to set a program keyboard interceptor (event handler) to track key events and run macro upon pressing wanted keys (Q and W) ?
Reply With Quote
  #4  
Old 03-08-2010, 18:06
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Hi.
Maybe you can get of to a start with this.
Put this in a module.

Code:
Option Explicit

Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Const W As Integer = &H57
Const Q As Integer = &H51


Sub saveKey()
    
    Dim keyW As Boolean, keyQ As Boolean, theKey As String
    If GetKeyState(W) < 0 Then keyW = True Else keyW = False
    If GetKeyState(W) < 0 Then keyQ = True Else keyQ = False
    
    If keyW = True Then
        theKey = "W"
    End If
    If keyQ = True Then
        theKey = "Q"
    End If
    
    SaveSetting "myApp", "Pref", "last_saved_key", theKey
    

End Sub
and run like this in the ThisMacroStorage for the SelectionChange event.

Code:
Private Sub GlobalMacroStorage_SelectionChange()

myModule.saveKey

End Sub
This would save the variable in the registry which you can access anytime.

-John
Reply With Quote
  #5  
Old 04-08-2010, 17:10
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 146
Default some thoughts

Hello
Great idea with GMS_SelectionChange !
Well, frankly handling of Q and W was a prototype of new macro.
I am trying write a universal macro (draft code below), which invokes by L,R,T,B,C,E-keys and working so:
- if it selected greather than one objects then selected objects just aligns, like common Corel Draw align operations;
- if one object selected then
- if it textshape then activates text alignment (Left, Right, Centered, fulljusTify etc.)
- if edit node mode then node alignment (Left, Right, Top, Bottom)

Main routine

Code:
sub LRTBCE_handler(ByVar KeyCode as long)
dim CurSelection as ShapeRange
dim AlignMode as byte
const cdrAnyShape = 255
    select case KeyCode
    L: AlignMode = 1
    R: AlignMode = 2
    T: ...         3
    B: ...         4
    C: ...         5
    E: ...         6
    end select

    set CurSelection = ActiveSelectionRange
    select case CurSelection.Count
    case 0
          exit sub ' no selection
    case 1
          if CurSelection.Shape(1).Type = cdrTextShape then
             AlingProc cdrTextShape, alignmode
             exit sub
          end if
          If (ActiveShape.Type <> cdrCurveShape) Or (ActiveTool <> 22) Then _
exit sub
          AlignProc cdrCurveShape, alignmode
    case else
          AlignProc cdrAnyhape, alignmode
    end case
end sub

private sub alignproc(cdrShapeType as integer, aligntype as byte)
const txtalign as array(cdrLeftAlignment, cdrRightAlignment, _
cdrFullJustify, cdrCenterAlignment...  ' textalignment ways
     select case cdrShapeType
          case cdrTextShape
              ... 'text alignment txtalign(aligntype)
          case cdrCurveShape
              ... ' node align
          case else 
              ... ' align some objects
     end select
end sub
I'll be gratefull for any help. Sorry, my English probably too poor...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 17:09.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com