web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Python script not retu...
Power Automate
Answered

Python script not returning a value

(1) ShareShare
ReportReport
Posted on by 13

Hello,

 

I am trying to run a python script that returns to me if the Caps Lock is enabled or not.

The script looks like this:

"import ctypes
def is_capslock_on():
    # Get the state of the Caps Lock key (0x14 is the virtual key code for Caps Lock)
    capslock_state = ctypes.windll.user32.GetKeyState(0x14)
    # If the least significant bit is 1, Caps Lock is on
    return capslock_state

print(is_capslock_on())"
 
The issue is that I run the script and the variable for error and the variable for output are blank.
And another issue is that the flow it's stopping at this action, because after that I put a Display message action and it's not working.
 
Thank you for your help.
I have the same question (0)
  • Verified answer
    NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @RaulPatcas !

     

    Alternate solution:

    Try this instead. Run this py script stored on machine using a PowerShell script.

    Flow details:

    NathanAlvares24_7-1719907913157.png

     

    I stored this py file in one of my folders. As seen below:

    NathanAlvares24_0-1719907568524.png

     

    The code is the same:

    NathanAlvares24_1-1719907590839.png

     

    PowerShell script:

    NathanAlvares24_3-1719907669504.png

     

    # Run the Python script and capture the output
    $output = & '%py_exe_path%' '%py_script_path%'
    
    # Display the output
    Write-Output $output

     

     

    Result:

    If my Caps Lock is ON:

    NathanAlvares24_9-1719907961683.png

     

    If my Caps Lock is OFF:

    NathanAlvares24_8-1719907947783.png

     

    Remember to use a Trim text action after any script as it returns another line as well.

     

    NathanAlvares24_6-1719907861681.png

     

    The full code of this flow (just copy paste into your flow):

     

     

    SET py_exe_path TO $'''C:\\Python312\\python.exe'''
    SET py_script_path TO $'''C:\\Users\\UserName\\check_capslock.py'''
    @@copilotGeneratedAction: 'False'
    Scripting.RunPowershellScript.RunPowershellScript Script: $'''# Run the Python script and capture the output
    $output = & \'%py_exe_path%\' \'%py_script_path%\'
    
    # Display the output
    Write-Output $output''' ScriptOutput=> PowershellOutput

     

     

    I hope this helps.

  • RP-27081204-0 Profile Picture
    13 on at

    Hello,

     

    Thank you for your time.

    This work-around is fixing my issue.

     

    Thank you!

     

    Regards,

    Raul Patcas

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 248 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 204

#3
Haque Profile Picture

Haque 179

Last 30 days Overall leaderboard