Determining Shift key status mid-sub

jbrouse

Active Member
Joined
Apr 28, 2005
Messages
329
Below is my code for creating a shape at the cursor position.

Currently, I use Ctrl+v to run this sub routine. I would like to modify the code so that if I press Ctrl+v to call the function and then hold down the shift key while I click, the shape will be connected to the previously placed shape. Is there a line of code or anything that I can place in the sub routine that will check whether the shift key is pressed AFTER the routine is called? (The problem is, if shift is pressed while Ctrl+v is pressed to call the sub routine, it sees it as Shift+Ctrl+V, which will not run the function)

So this is how it should go.

User presses Ctrl+v to call the sub routine. User then clicks on the screen to paste the shape at the cursor position.

-OR-

User presses Ctrl+v to call the sub routine. User then presses the shift key and clicks on the screen which pastes the shape at the cursor position, then adds a connector shape to the previous shape.

Code:
Sub Connect_Shape()

Dim x As Single, y As Single, ShapeWidth As Single, ShapeHeight As Single
    Dim EndCon As Integer
    
    Application.ScreenUpdating = False
    
    
    If ActiveSheet.Name <> "PROCESS FLOW" Then Exit Sub
    
    ShapeWidth = 20
    ShapeHeight = 20
    
    Call GetPoints(x, y)                         'Determine x,y position of cursor
    
    x = x - (ShapeWidth / 2)
    y = y - (ShapeHeight / 2)
    
    SetCounter
    'ShiftKeyState = GetKeyState(vbKeyShift)  'Where can I put this code?

    Select Case Worksheets("PROCESS FLOW").Range("BL3").Value
        Case "PARTS / MATERIAL"
            ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
            Exit Sub
        Case "PROCESS"
            ActiveSheet.Shapes.AddShape(msoShapeOval, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
        Case "INSPECTION"
            ActiveSheet.Shapes.AddShape(msoShapeDiamond, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
        Case "PROCESS / INSPECTION"
            ActiveSheet.Shapes.AddShape(msoShapeOval, x, y, ShapeWidth, ShapeHeight).Name = "a" & counter
            ActiveSheet.Shapes("a" & counter).Select
            Selection.Characters.Text = counter
            With Selection.Font
                .Size = 7
            End With
            With Selection
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
            End With
            ActiveSheet.Shapes.AddShape(msoShapeDiamond, x + 2, y + 2, ShapeWidth - 4, ShapeHeight - 4).Name = "b" & counter
            ActiveSheet.Shapes("b" & counter).Select
            Selection.ShapeRange.Fill.Visible = msoFalse
            ActiveSheet.Shapes.Range(Array("a" & counter, "b" & counter)).Select
            Selection.ShapeRange.Group.Name = "Pr0" & counter
        Case "ASSEMBLY"
            ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x, y, ShapeWidth, ShapeHeight).Name = "Pr0" & counter
            ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, x + 5.5, y + 8, ShapeWidth - 11, ShapeHeight - 11).Name = "Pr0" & counter
            Exit Sub
    End Select
    
        If ShiftKeyState And &H8000 Then
            ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 461.25, 204#, 1.5, 22.5).Name = "C0" & counter
            ActiveSheet.Shapes("C0" & counter).Select
            Selection.ShapeRange.ConnectorFormat.BeginConnect ActiveSheet.Shapes("Pr0" & counter), 1
            Selection.ShapeRange.ConnectorFormat.EndConnect ActiveSheet.Shapes("Pr0" & counter - 1), 1
            Selection.ShapeRange.ZOrder msoSendToBack
            
            x = ActiveSheet.Shapes("Pr0" & counter - 1).Left
            ActiveSheet.Shapes("Pr0" & counter).Left = x
            y = ActiveSheet.Shapes("Pr0" & counter - 1).Top + 30
            ActiveSheet.Shapes("Pr0" & counter).Top = y
        End If
        
        
Default:

        ActiveSheet.Shapes("Pr0" & counter).Select
        Selection.OnAction = "Add_Detail"
        
        If ActiveSheet.Shapes("Pr0" & counter).AutoShapeType <> -2 Then
            Selection.Characters.Text = counter
            Selection.Font.Size = 7
            With Selection
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
            End With
        End If
    
        ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, x + 35, y + 2.5, 0, 0).Name = "T0" & counter
        ActiveSheet.Shapes("T0" & counter).TextFrame.Characters.Text = "INSERT TEXT HERE"
        
        Application.ScreenUpdating = True
        
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,203,455
Messages
6,055,540
Members
444,794
Latest member
HSAL

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top