Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to perform a key press 'Enter' in Python?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
acupen
225 Views, 3 Replies

How to perform a key press 'Enter' in Python?

After most of the operation, I have to press 'Enter' to finish, 'Enter' is not in a easy position to press.

Is that a way I can write a python script to perform a 'Enter' press? then binding it to 'SPACE', much more easy to press.

I have already write some shortcut in Python to make it easy to work.

 

 

For example, I just press a 'G' button then I can go back to home view. It's quite a easy command like below:

 

def command_execute(args: adsk.core.CommandEventArgs):
    futil.log(f"{CMD_NAME} Command Execute Event")

    ## Go HOME!!!!
    app.activeViewport.goHome()

 

Then set a shortcut 'g' in Fusion, then every time I press 'G', it go back to home view.

 

So how can I send a 'Enter' in python to Fusion interface?  imitate a key press 'Enter' then send it to Fusion to finish an operation?

 

The only information I got now is the keycode of 'Enter'. 

EnterKeyCode16777221Enter

 

Thanks in advanced if you can share some experience with me :slightly_smiling_face:

acupen_0-1733406538800.png

 

Labels (4)
3 REPLIES 3
Message 2 of 4
Jorge_Jaramillo
in reply to: acupen

Hi,

 

The pynput package can be used to simulate keystrokes.

Here is a snipped code for the ENTER key:

from pynput.keyboard import Key, Controller
keyboard = Controller()

keyboard.press(Key.enter)
keyboard.release(Key.enter)

 

I wonder how are you going to trigger its execution: from where?  under which conditions?

 

Regards,

Jorge Jaramillo

 

Message 3 of 4
acupen
in reply to: Jorge_Jaramillo

Trigger a script you write in Fusion is easy.

 

1. Run it as Add-Ins,

acupen_0-1733446293755.png

 

2. inside your add-ins, you write several commands. Then 'Change Keyboard Shortcut...'

acupen_1-1733446394460.png

 

3. just assign a shortcut key for the command(underneath is a script) your write. Then it's done. 

During fusion running, every time you press 'g', you trigger your script once ...

acupen_2-1733446495000.png

 

 

Message 4 of 4
acupen
in reply to: Jorge_Jaramillo

and Thanks for your reply.

I figure out a way to achieve what I want to do, beyond Fusion.

 

Just install a microsoft enhance tool:  PowerToys.

https://github.com/microsoft/PowerToys/releases/tag/v0.86.0

then you can switch any keypress with other key in a system level.

 

I just switch the 'Space' key with 'Enter', everything is done now. 

 

Thanks again for you help.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report