# Capture keystroke/keycode on power table

**URL:** <https://forum.inductiveautomation.com/t/capture-keystroke-keycode-on-power-table/12707>\
**Category:** Ignition\
**Created:** [February 22, 2017, 11:01pm UTC](https://forum.inductiveautomation.com/t/capture-keystroke-keycode-on-power-table/12707 "2017-02-22T23:01:02Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Ryan\_Shaw](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Ryan\_Shaw](https://forum.inductiveautomation.com/u/Ryan_Shaw)\
**Post date:** [March 23, 2023, 8:13pm UTC](https://forum.inductiveautomation.com/t/capture-keystroke-keycode-on-power-table/12707/10 "2023-03-23T20:13:48Z")

</div>

A minor improvement to this discussion: here's a working script formatted correctly that can be copy/pasted into a power table's initialize function, ready-to-go. I think a broader usage is also more clearly demonstrated by using an example with the CTRL key:

```auto
# PowerTable initialize function
# Adds a hotkey action bound to the keystroke "CTRL+D"
from javax.swing import AbstractAction, JComponent, KeyStroke
class MyAction(AbstractAction):
	def actionPerformed(self, event):
		print 'Success'
a = MyAction()
k = KeyStroke.getKeyStroke("control D")
self.registerKeyboardAction(a, k, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)

```

Edit: this is also relevant for people wanting to add hotkeys to a table with editable cells:

> [@Power Table Stray Typing](https://forum.inductiveautomation.com/t/power-table-stray-typing/18975):
>
> I could be completely missing something simple with the Power Tables. But is there any way to prevent stray typing from being accepted in a Power Table cell? I would like to make it so the user is forced to double click or press Enter on a cell to be able to actually edit it. However, even with the Edit Click Count property set to 2, it will allow stray typing in a cell that doesn’t have focus but is selected/highlighted This can be problematic for us with operators accidentally bumping keys…

---

_[View the full topic](https://forum.inductiveautomation.com/t/capture-keystroke-keycode-on-power-table/12707)._
