![]() |
|
#1
|
|||
|
|||
![]()
Hi All,
Im writting scripts for some gui elements such as complex gradient fills. Using these for example: Red... a series of 4 different red gradient fill scripts attached to 4 seperate buttons . Green... a series of 4 different green gradient fill scripts attached to 4 seperate buttons . Blue, Gold, Orange and lots more. each the same but with different colors. This all works well but starts to crowd the gui. So I was wondering how to make it so, when a particular button- red for example - was pushed, holding down the CTRL key or ALT key or Shift etc. or combinations of all would effect which script runs. I hope thats not too confusing ![]() best regards Andy |
#2
|
||||
|
||||
![]()
Andy,
You can do it fairly easily by using WIndows API function GetAsyncKeyState. You can quiery the state of any key of the keyboard. Here is a simple macro which generates a random rectangle each time it is called. And the fill of the rectangle depends on which modifier key is depressed. Shift would add red, Ctrl - green and Alt - blue. Combination of the keys will produce mix of the colors. The only complication is that ALT is used in CorelDRAW UI to move controls on toolbars, so you can't click a button with ALT depressed and launch a macro. This won't work. However you can go to Tools>Visual Basic>Play and then start the macro and keep ALT down. If this is an issue, you should choose another key for this... Code:
Option Explicit Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private Const VK_SHIFT = &H10 Private Const VK_CONTROL = &H11 Private Const VK_MENU = &H12 Private Function IsShiftPressed() As Boolean IsShiftPressed = (GetAsyncKeyState(VK_SHIFT) < 0) End Function Private Function IsCtrlPressed() As Boolean IsCtrlPressed = (GetAsyncKeyState(VK_CONTROL) < 0) End Function Private Function IsAltPressed() As Boolean IsAltPressed = (GetAsyncKeyState(VK_MENU) < 0) End Function Public Sub MyCoolMultifunctionalMacro() Dim r As Long, g As Long, b As Long Dim s As Shape r = 0 g = 0 b = 0 If IsShiftPressed() Then r = 255 If IsCtrlPressed() Then g = 255 If IsAltPressed() Then b = 255 Set s = ActiveLayer.CreateRectangle2(Rnd() * 4, Rnd() * 5, Rnd() * 4, Rnd() * 5) s.Fill.UniformColor.RGBAssign r, g, b End Sub |
#3
|
|||
|
|||
![]()
HI Alex, First off Thanx for being here! Second. I just read and am eager to try... will post back when finished.
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Simple Bar code generator | Webster | Code Critique | 2 | 06-09-2010 01:41 |
Text ENCODE | Craig Tucker | CorelDRAW/Corel DESIGNER VBA | 10 | 26-01-2005 13:59 |
How to use events from CorelDRAW.Document in my code? | me | CorelDRAW/Corel DESIGNER VBA | 2 | 30-10-2004 02:49 |
How can I extract a piece of a bitmap object using VBA code | oswaldon | Corel Photo-Paint VBA | 2 | 25-04-2004 19:37 |
Generic code to process all shapes in a document | glennwilton | CorelDRAW/Corel DESIGNER VBA | 0 | 05-09-2003 03:13 |