I tried making an addin having below code where I want the user to press a predefined key and the "required_code" should run on the selected features.
import arcpy
import pythonaddins
class Key1(object):
"""Implementation for Key Listener_addin.Key1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onKeyUp(self, keycode, shift):
print("Process Started")
print("Key pressed: " + keycode)
self.checked = True
#required_code goes here with messagebox
print("Process Completed")
self.checked = False
However The above code doesn't do anything, not even printing first line.
How could I enable this addin to run the code on pressing a key? Also how can I print which key is pressed by user?
Could you correct me on what I am doing wrong?
UPDATE:
I have tried to define keycode using msvcrt but it is still not working. My updated code is:
import arcpy
import pythonaddins
from msvcrt import getch
class Key1(object):
"""Implementation for Key_Listener_addin.Key1 (Button)"""
def __init__(self):
Key1.enabled = True
Key1.checked = False
keycode = msvcrt.getch()
def onClick(self):
if Key1.checked == True:
Key1.checked = False
elif Key1.checked == False:
Key1.checked = True
def onKeyUp(self, keycode, shift):
if Key1.checked == True:
if keycode == 85:
print(keycode)
85 is the ASCII value for 'U'.