keydownpowerbuildereventtriggerdatawindow

Triggerevent doesn't do anything on a parentwindow


I have an old project made with powerbuilder 10.5. I'm trying to create a keydown or dwnkey event to trigger a commandbutton to execute a print command.

The parentwindow (w_waybill) has some datawindows, is a form to create waybills, and it has 3 commandbuttons, Close, Save and Print. The Print button is cb_2

So I've created an event (tried both pbm_keydown and pbm_dwnkey) inside the parentwindow w_waybill like this:

if KeyDown(KeyF9!) then  cb_2.triggerevent(clicked!) end if 

but this doesn't trigger anything, so instead of trying to trigger the commandbutton, I've tried this to make a messagebox:

if KeyDown(KeyF9!) then  MessageBox('Hi','pbm_keydown') end if 

This doesn't do anything.

I don't know what I'm missing here. The form is tabular and once open it places the pointer to the first datawindow. Do I have to specify some global stuff to point the parent window on the keydown script?

I want to press F9 to avoid the user to use the mouse to click the button Print. I already have marked the Save button as primary so I can't use that.


Solution

  • A quick and easy fix in your situation is to attach a menu to your window and you can make it visible or not.

    You assign KeyF9! as the shortcut to one item menu.

    The script in the item menu will trigger the button click event on the parent window. You don't need to test for the KeyF9! since that key is defined as a shortcut.

    Shortcut in a menu always has priority so it's not important which control has the focus.

    menu definition in powerbuilder