• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Examples and Tutorials
  • Using Python for Mouse Tracking

Using Python to Plot Variables Connecting Many Variables at Once

Using Python for Mouse Tracking

Using Python for Mouse Tracking

This example demonstrates how to connect and send values to CDP automation system using Python in CDP Studio, the independent automation software for open PC-based real-time distributed control systems with NoCode setup within the IDE.

The example launches Python script as a standalone program, that connects to CDP application and sends mouse movements to CDP signals.

Project Overview

The project consists of a very simple CDP application with two input CDPSignals - MouseX and MouseY. The project folder also contains a simple Python script named sendmousemoves.py. This script will connect to CDP via StudioAPI protocol and find the signals MouseX and MouseY. Then it will activate system mouse movement listener (using pynput module) that will send new value to MouseX and MouseY on every mouse move.

The goal of the example is to demonstrate how easy it is to connect and send values to CDP using Python cdp-client module. You just have to initialize cdp-client with the network location of the CDP application (host and port), call find_node to connect to the required signals and create and hook functions that are called when system is connected and signals are found. New values can be sent to found CDP signals using set_value function.

Note: This simple Python script is resistant to CDP application restarts or connection failures. While running, it will try automatically to reconnect and will continue sending mouse movement values once reconnected.

How to Run the Example

To run the example from CDP Studio, open Welcome mode and find it under Examples. Next, in Configure mode right-click on the system project and select Run & Connect. See the Running the Example Project tutorial for more information.

PythonRunner Component

To be able to run this example on your computer without any preparation or manual work the Python script is launched automatically on CDP application startup. To achieve this, a separate component named PythonRunner is added into the application. PythonRunner is actually a CDP ExternalControlBroker component, that uses LocalCommandRun request to launch the example Python script as separate process.

How to Prepare to Run the Example in Your Python Environment

This example uses the Python environment bundled with CDP Studio to run the example.

However, the recommended way to run Python scripts is to run them separately from Studio. For that you have to:

  • verify that Python interpreter is installed in your computer and install it, when missing.
  • install Python CDP client by entering the following command in your computer command prompt
    pip install cdp-client
  • install Python mouse and keyboard monitoring module pynput by entering command in your computer command prompt
    pip install pynput
  • locate the Python script from project folder, for example by typing sendmousemoves.py into the locator box on the lower left area of the CDP Studio window
  • copy the file that opened in Code mode editor via copy pasting its text or via menu
    File->Save "sendmousemoves.py" As...
  • start the CDP application again and look in the Application Output pane for a line like
    10:40:29.700 StudioAPIServer: listening on 127.0.0.1:7689
  • set the IP and port of the StudioAPIServer which the copied script reads from the environment variable StudioAPIURI and run the script, by executing following commands.

    Windows:

    set StudioAPIURI=127.0.0.1:7689
    python sendmousemoves.py

    Linux:

    export StudioAPIURI=127.0.0.1:7689
    python sendmousemoves.py

Troubleshooting

What to do when command "pip install cdp-client" fails?

Some systems might not include setuptools and wheel packages by default. Run

pip install setuptools wheel

and try to install CDP client again.

Using Python to Plot Variables Connecting Many Variables at Once

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top