Where are actions of buttons' long pressing stored? I want to remap the long press action  of the menu button to open the dialog box that appears when the power button is long pressed. I know the keybinds are stored mainly in /system/usr/keylayout/Generic.kl but I can't find where the long press settings are stored.

The settings menu allows me to remap the action of long pressing, but it doesn't offer an option to invoke the dialog box of power menu. As far as I am concerned, the Android API doesn't provide any option to access the power button so I need to change the action inside proper system files. Also, the API doesn't allow me to map the screenshot taking what is the main purpose of mine. So I want either to map the dialog box of power menu or screenshot taking to the long press action of menu button.

I own Samsung Galaxy S3 with Cyanogenmod 14.1 Android 7.1.1
So there appears to be several apps on the app store.

Button Mapper: Remap your keys is one such example.
Buttons remapper (no root) is another.