# Using keyCode when Processing imported as p

**URL:** <https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652>\
**Category:** Processing.py\
**Created:** [June 20, 2022, 3:40pm UTC](https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652 "2022-06-20T15:40:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonc8](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@simonc8](https://discourse.processing.org/u/simonc8)\
**Post date:** [June 20, 2022, 3:40pm UTC](https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652/1 "2022-06-20T15:40:12Z")

</div>

I’m curious about why keyCode doesn’t seem to recognise keypresses when you import processing using an alias. I am using trinket, so that may be an issue.

With this simple code

```auto

from processing import *

def keyPressed():
  print(keyCode)
 
run()

```

I can derive the keyCode value for any key I press. But if I change the import style:

```auto

import processing as p

def keyPressed():
  print(p.keyCode)
  
p.run()

```

the code runs but it prints the word unknown surrounded by less than and greater than signs  
whatever key I press.

Grateful for enlightenment.

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [June 22, 2022, 7:12pm UTC](https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652/2 "2022-06-22T19:12:44Z")

</div>

Cheers @simonc8 !

The Trinket implementation of Processing + Python is based on Skulpt + ProcessingJS  
And ProcessingJS is kind of a zombie, unfortunately ([GitHub - processing-js/processing-js: A port of the Processing visualization language to JavaScript.](https://github.com/processing-js/processing-js)) so I couldn’t find any documentation about `keyCode`.

Maybe you could try [pyp5js: drawing with Python 3 | pyp5js](https://berinhard.github.io/pyp5js) which is a work in progress, but at least you can open an issue if it doesn’t work…

And there are other options to explore, like [http://p5py.com](http://p5py.com) (Brython based)  
More options at [Python + Processing table](https://abav.lugaralgum.com/Resources-for-teaching-programming/)

---

<div class="post-metadata">

**Author:** ![simonc8](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@simonc8](https://discourse.processing.org/u/simonc8)\
**Post date:** [June 22, 2022, 7:33pm UTC](https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652/3 "2022-06-22T19:33:05Z")

</div>

Hi thanks for the information.

Do you know if there is a way to use the processing library with Python Idle? If I `import processing` it says ‘No module named processing’ so I suppose it needs installing, but using `pip install processing` doesn’t work. Do I need a different install command?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [June 22, 2022, 7:40pm UTC](https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652/4 "2022-06-22T19:40:27Z")

</div>

Processing is a Java library; hence it’s not available via `pip`. You could use [py5](http://py5.ixora.io/) instead (`pip install py5`). Note that you’ll need to have [Java installed](http://py5.ixora.io/content/install.html#install-java) on your computer.

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [June 22, 2022, 7:49pm UTC](https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652/5 "2022-06-22T19:49:51Z")

</div>

Full disclosure: @tabreturn and me, we are fans of [py5.ixora.io](http://py5.ixora.io) 😃

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 25, 2022, 4:43am UTC](https://discourse.processing.org/t/using-keycode-when-processing-imported-as-p/37652/6 "2022-06-25T04:43:26Z")

</div>

PyScript alpha version was recently released and I’ve converted an online sketch for it: 🐍

> [@Converting coding challenge 'Self-avoiding walk backtracing' from p5.js to Processing (Java)](https://discourse.processing.org/t/converting-coding-challenge-self-avoiding-walk-backtracing-from-p5-js-to-processing-java/35047/21):
>
> Python is now a full browser client language w/ PyScript: So again I couldn’t resist converting my previous RapydScript sketch “Self Avoiding Walk II” to PyScript. I’ve also added Python type hints to the whole code: All 3 JS Processing flavors run on PyScript just like CoffeeScript & RapydScript previous versions: You can [click here](https://api.glitch.com/project/download/?authorization=3d2d3e71-2277-421f-9d6a-38d0f41b0522&projectId=3dc3a6ae-9818-441a-8f7e-b1d50e7199c3) to download the full sketch so you can edit & run it somewhere else. And go to the link below to view it fullscreen: [https://Self-Avoiding-Walk-II-PyScrip…](https://Self-Avoiding-Walk-II-PyScript.Glitch.me/)
