Unable to close modal dialog - modal-dialog

I'm trying to call a screen as a popup. The screen type is set to Modal dialog box and I'm able to call the screen, but unable to close it. Nothing happens when I click on the little cross. The next screen is set to 0.
The screen I'm calling as a popup, doesn't contain any buttons, not any hard coded ones anyway. Any ideas what I'm doing wrong?
I'd also like the screen it returns to, to be refreshed (so it loads the PBO again). How do I do that?
Here is the code:
MODULE werkende_knoppen_subscreen INPUT.
CASE ok_code.
WHEN 'X'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.

You should be checking for the 'EXIT' (or, in your case for the custom close button, 'X') user command in the PAI part of your popup.
For example:
MODULE user_command_0010 INPUT.
ok = sy-ucomm.
CLEAR sy-ucomm.
CASE ok.
WHEN 'EXIT' OR 'X'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.

This is a non-documented feature but in a modal dialog box (popup), the top-right button to close the popup is assigned the F12 key, so you must assign this key to a function code and process it as any other function code.
Step-by-step procedure:
1) Create the ABAP program (transaction code SE38 or SE80)
REPORT.
CALL SCREEN 100 STARTING AT 10 10 ENDING AT 60 20.
MODULE status_0100 OUTPUT. " <=== called "before output"
SET PF-STATUS '0100'. " <=== choose the GUI status
ENDMODULE.
MODULE user_command_0100 INPUT. " <=== called "after input" (after user action)
IF sy-ucomm = 'CANCEL'. " <=== the function code you chose in your GUI status
SET SCREEN 0. " <=== 0 is a special number which ends "CALL SCREEN"
ENDIF.
ENDMODULE.
Note: SET SCREEN 0 is to close the dialog box (0 means "the current dynpro sequence is ended") ; if you have a complex screen you may also use LEAVE TO SCREEN (which is equivalent to the 2 statements SET SCREEN + LEAVE SCREEN).
2) Create the screen 0100 (transaction code SE51 or double-click 0100 behind CALL SCREEN)
Screen type: modal dialog box
Flow logic:
PROCESS BEFORE OUTPUT.
MODULE status_0100.
PROCESS AFTER INPUT.
MODULE user_command_0100.
3) Create the GUI status 0100 (transaction code SE41 or double-click 0100 behind SET PF-STATUS)
Status type: dialog box
Assign the F12 key to an arbitrary function code (I chose the name CANCEL), and activate this function code (button "Function Code"):
4) Test
Run the program, you may now click the top-right button (or press F12 if you prefer) which closes the modal dialog box:

Related

WinActivate does not work as expected. Re-activating focus to the starting window

I am having some serious struggles fully grasping the control on activating windows and forcing their focus and foremost position.
In order to debug a larger script I made a separate script to test the use of WinActivate and again I am observing frustrating behaviour as it either all together ignores the title I have defined or is failing in some other way. In the smaller test script I am simply requesting that the window in which the hotkey was triggered be set as active after another action, specifically an input box
Below is the simple code for testing:
F10::
SetTitleMatchMode, 1
DetectHiddenWindows, Off
WinGetTitle, startTitle, A
msgbox % "Start Title = <" . startTitle . ">"
;WinActivate, startTitle
inputbox, mode, Test box, Testing,,260,160
sleep 500
WinActivate, startTitle
Return
This code does not properly activate the starting window. For example I execute the hotkey in an empty notepad window and upon submitting blank into the input box the focus becomes notepad++ on my second monitor. The second time I press the hotkey from within notepad (or another application) notepad does not lose focus. In a third execution I begin from notepad again and after the input box appears I switch the focus to another window. I again submit blank to the inputbox but that new window remains the focus and notepad is not activated or brought to the foremost position.
Can someone please explain to me what is going on with WinActivate?
I was having similar frustration with unexpected results making a windows script host file and I think I must be missing some fundamental detail in windows.
You are trying to activate a window that start with the literal text "startTitle".
You forgot(?) to either enter expression syntax with % or use the legacy way of referring to a variable %startTitle% (please don't use legacy).
Extra stuff:
You shouldn't specify SetTitleMatchMode and DetectHiddenWindows inside your hotkey statement. There is no need (unless there actually is) to set those every time you hit the hotkey. Just specify them at the top of your script once.
Both of them are useless for you though, below I'll show why. Also DetectHiddenWindows is already off by default.
WinGetTitle is not good to use for this. What you actually want to do is get the hwnd of the window you wish by using e.g. WinExist().
And then refer to the window by its hwnd. Much better than working with window titles, and impossible to match the wrong window as well. To refer to a window by its hwnd, you specify ahk_id followed by the hwnd on a WinTitle parameter.
And lastly, the concatenation operator . is redundant. Of course you may prefer to use it, but in case you didn't know, it can just be left out.
Here's your revised code:
F10::
_HWND := WinExist("A")
MsgBox, % "Start hwnd = <" _HWND ">"
InputBox, mode, Test box, Testing,,260,160
Sleep, 500
WinActivate, % "ahk_id " _HWND
Return

autohotkey type in another window with gui

Autohotkey Example Needed
Need some help, please. I've searched and can't seem to find an example of what I need.
What I want to do is create a ahk dialog box with a button (I can do this part), and when I click on it, it will type some text into another window. Basically, I want want to offload the "shortcut" to a "mouse click". But, without mapping a shortcut.
Something like this:
When user clicks BOX1, "text" is stored. Then, when user clicks elsewhere, vBOX1 is typed into the cursor location of the window activated by that click
I hope I'm explaining this succinctly. Any help would be appreciated.
Here are two possible alternatives:
First alternative expands #scso's suggestion:
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
Send, %vBOX1%
return
Now this may seem fine but what it actually does is type the text EVERY time you click the mouse in ANY window. Let's put an additional check so if vBOX1 is empty it doesn't type anything.
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
If (vBOX1 != "")
{
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
}
return
Second alternative:
You use the mouse clicks normally and the text gets typed only when you do Control + Click.
So in order to type the text you need to click once to select the window and then control+click to do the actual typing
~^LButton::
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
return
You can expand both alternatives by adding commands for detecting the active window and then typing the text or changing the mouse click combination to something else.

Using Autohotkey to select an option from a dropdown on a webpage

I am trying to write a script to select something from a drop down on a webpage and then tab to the next option and input text, then enter. FYI, this is my first script.
I have to create groupings and select from different areas. I have seen places where people have scripts to select certain things but says that can only work in IE browser. I will be using either firefox or chrome but not IE.
^q::Click, 284, 427 ;
Send {Up 10}
Send {Tab} ;
sleep 50 ;
Send BWI{Enter}
return
So what I want it to do is when I press control q, it will go to position 284,427 and click. The dropdown defaults to the bottom option. So I put in code to go up 10 which would select the 10th option from the bottom. Then I want it to tab. That will select the 10th option and go to the next text box at which point it will enter the text BWI and then enter. The BWI is a filter that will show all of the items that have BWI in their name.
Currently, it goes to the dropdown and clicks. Then it does nothing else.
To have more than one command executed by a hotkey, put the first line beneath the hotkey definition and make the last line a return:
^q::
Click, 284, 427
Send {Up 10}
Send {Tab}
sleep 50
Send BWI{Enter}
; ...
return
https://autohotkey.com/docs/Hotkeys.htm#Intro

How can I wait for only one of three events (mouse input, keyboard input, or WinWaitClose) in AutoHotkey?

In my scenario, either a window will close automatically, or the user will provide an input via mouse or keyboard.
If the window closes automatically, I want to open a PDF. This is easy:
WinWaitClose, ahk_id %cmdHwnd%
Run, "C:\Program Files\SumatraPDF\SumatraPDF.exe" "%path%\cv.pdf"
But if the window doesn't close automatically (i.e. the PDF failed to compile), then the user's going to close that window manually, e.g. hit Enter or click the close button. In this case, I do not want the above WinWaitClose to trigger!
So another way of putting my question is, how do I "cancel" a WinWaitClose listener upon mouse or keyboard input?
I suppose you could rely on the Seconds timer in WinWaitClose, and if that fails, you can rely on the ErrorLevel which will be set to 1.
; Set WinWaitTimer to wait 2 seconds before timing out.
WinWaitClose, ahk_id %cmdHwnd%,, 2
if (ErrorLevel) {
; Do something.
}
else
{
Run, "C:\Program Files\SumatraPDF\SumatraPDF.exe" "%path%\cv.pdf"
}

How to make "up"key complete the already typed command from history, not pick any that contains the already typed part?

Until recently, when I typed
x=1;
2*x;
x
into the command window (without pressing enter after x) and pressed the arrow up key, the line was completed with the last command in the history that started with the already typed part, here the first line. Recently, the behavior changed to replacing it with the last command that contains the already typed part, i.e. the second line in the example, without me knowingly changing any setting.
How do I get the old behaviour back? In "Perferences->Keyboard->Shortcuts" (as per this question) the up key is associated with "Cursor up" and "Previous History Command", but the description of the latter is ambiguous regarding the expected behaviour when something is already typed into the command line.
First, make sure that the command history window is docked (If you have a floating window every time you press up then it is not docked. There is a drop-down menu - little circle with a triangle inside. Open the menu and select "Dock").
Once\if the window is docked, open the menu again and make sure that "Match Beginning" is selected and not "Match Anywhere".