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 01-01-2005, 18:29
xombie
Guest
 
Posts: n/a
Default How to implement Ctrl & alt keys in code

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
Reply With Quote
  #2  
Old 05-01-2005, 23:14
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: How to implement Ctrl & alt keys in code

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
Reply With Quote
  #3  
Old 08-01-2005, 12:17
xombie
Guest
 
Posts: n/a
Default Thanx

HI Alex, First off Thanx for being here! Second. I just read and am eager to try... will post back when finished.
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

Similar Threads
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


All times are GMT -5. The time now is 05:54.


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