SendKeys is the VBA command to literally send keystrokes to the interface, as if they were being typed on a keyboard. It’s a useful tool if you know how to use it. The CATIA VBA SendKeys syntax is simple: Access the command SendKeys and follow it with a string:

SendKeys “Cut”

You can find the syntax for the string arguments by using the object browser in the VBA editor (with VBA editor open hit F2 then search for “SendKeys” then right-click on Sendkeys and choose Help). For keystrokes that do not appear as characters (i.e. TAB, ENTER, etc), use the braces to encapsulate the string.

SendKeys “{Enter}”
It’s a good idea to code all SendKeys commands following a Display Refresh. See sample code below:

SubCATMain()

CATIA.StartCommand(“Disassemble”)

CATIA.RefreshDisplay = True

SendKeys “{ENTER}”

End Sub

 

Often, without the Display Refresh, the keystrokes will be sent so fast that the interface will still be processing the last line of code. Adding “CATIA.RefreshDisplay = True” will slow the process down and make SendKeys wait until it’s ready.

Other advice: You might want to double check for caps lock state. Other times you may need to create an object and use that with the SendKeys:

Dim WSShell
Set WSShell = CreateObject(“WScript.Shell”)

WSShell.SendKeys “c:FrmActivate”
WSShell.SendKeys “{ENTER}”

 

Below is a table of useful Sendkeys:

 

Key Code
Backspace {BACKSPACE}, {BKSP} or {BS}
Break {BREAK}
Caps Lock {CAPSLOCK}
Delete {DELETE} or {DEL}
Down Arrow {DOWN}
End {END}
Enter {ENTER} or ~
Escape {ESC}
Help {HELP}
Home {HOME}
Insert {INSERT} or {INS}
Left Arrow {LEFT}
Num Lock {NUMLOCK}
Page Down {PGDN}
Page Up {PGUP}
Print Screen {PRTSC}
Right Arrow {RIGHT}
Scroll Lock {SCROLLLOCK}
Tab {TAB}
Up Arrow {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16

 

To specify characters combinations use the following codes:

Key Code
Alt %
Ctrl ^
Shift Lock +

For example to specify CTRL and C, the code would be object.SendKeys “^C” and for SHIFT F5 object.SendKeys “+{F5}”. To specify multiple combination sets such as ALT A Z, you use parentheses, for example, object.SendKeys “%(AZ)”.