Remapping Esc key to discard a popup

Get help with using AutoHotkey and its commands and hotkeys
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Remapping Esc key to discard a popup

26 Nov 2018, 03:12

Hello,
I'm using a tool called PhraseExpress to help me enter similar sentences using keyboard.
This tool shows a small popup containing text snippets that match my input.
Occasionnally, I need to discard the popup. I would like the Esc key to allow me to do this.
The issue without remapping the key is that Esc discards the popup but sends the Esc key to the host application.
I need Esc while popup is displayed to just discard the popup

The window characteristics of the popup are

ahk_class TexForm
ahk_exe phraseexpress.exe

I have written the below script but is doesn't work :

$Esc::
IfWinActive, ahk_class TExForm
{
;keystroke to discard the menu
SendInput, {Left}
}
Else
{
SendInput, {Esc}
}
return

Can someone help ?
Thanks
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: Remapping Esc key to discard a popup

26 Nov 2018, 05:00

What is the title on the popup? Use that title instead of ahk_class value.
Because the host application and the popup both might have the similar ahk_class and ahk_exe values.

What happens when you send {left}?
Do you also have to send {enter}? (I'm assuming there is an "OK" button that needs to be clicked)
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

26 Nov 2018, 05:09

Actually the popup has no title. Just a list of corresponding text snippets.
{left} discards the popup
{Enter] chooses the selected entry
There is no OK button
Attached is a sample (French text)
2018-11-26_11-05-27.png
2018-11-26_11-05-27.png (3.25 KiB) Viewed 738 times
-Pierre
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: Remapping Esc key to discard a popup

26 Nov 2018, 05:13

Try removing the "$" sign at the start of your code.
Also try "Winactivate, ahk_class TExForm".

Code: Select all

Esc::
IfWinActive, ahk_class TExForm
{
;keystroke to discard the menu
Winactivate, ahk_class TExForm
SendInput, {Left}
}
Else
{
SendInput, {Esc}
}
return
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

26 Nov 2018, 05:17

Actually I don't think I should remove the $, since I'm sending Esc within a routine that processes Esc, so an infinite loop will occur.
Tried it and doesn't work.
It is apparently difficult to detect when the popup is displayed or not.
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

26 Nov 2018, 07:36

Does someone have a suggestion on how to detect that strange popup ?
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: Remapping Esc key to discard a popup

26 Nov 2018, 07:57

I use SciTE4AutoHotkey
it has a "Active Window Info" program that gives you these info

http://fincs.ahk4.net/scite4ahk/
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

26 Nov 2018, 11:04

Thanks. Looks basically the same as Windows Spy included in AutoHotkey. That didn't help much more. Sorry
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

27 Nov 2018, 04:57

Any other idea, anyone, on how catch that bloody popup ? Thanks
The WindowProbe script gives :

Unique ID: ahk_id 0x41664
Title:
Class: ahk_classTExForm
Control:
Active Control:

Does someone has an idea to know whether the popup is displayed (or hidden), and how to discard it (giving it focus and typing {left}) ?
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

27 Nov 2018, 05:45

The following code works ...

$Esc::
Sleep, 100 ; 1 second
uid = WinExist(""ahk_class TExForm")
If uid
{
WinActivate, ahk_id %uid%
SendInput, {Left}{Right}
}
Else
{
SendInput, {Esc}
}
return

... however, the next issue is t popup is always found (whether visible or not). So when the popup is not visible the {Esc} key is never sent.
Help !

PS: I have Detecthiddenwindows to off
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

27 Nov 2018, 08:45

Does someone know about a trick to determine whether the popup is actually visible on screen ?
Apparently WinExist() is not reporting whether it's visible or not.
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

27 Nov 2018, 12:17

Seems I'm alone or no one is interested... Sigh
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: Remapping Esc key to discard a popup

27 Nov 2018, 12:20

is your code at the end of the script ?
try placing the code at the start or your script or before the popup appears
list
Posts: 137
Joined: 26 Mar 2014, 14:03
Contact:

Re: Remapping Esc key to discard a popup

27 Nov 2018, 12:45

Not an answer to your question but why use such a program when AutoHotkey can also send texts via hotstrings, hotkeys and menus?

AHK alternatives: AutoComplete, TypingAid and Lintalist may be of interest, see https://github.com/ahkscript/awesome-AutoHotkey#typing
and intellisense everwhere https://autohotkey.com/boards/viewtopic.php?f=6&t=45684 - a TypingAid fork by the looks of it
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

28 Nov 2018, 03:42

@list: Thanks will have a look ! Just a comment that the tool I'm using (phraseexpress.exe) auto learns the frequently typed snippets. Do you know about a script that does same ?
@hymal7: Code is at the beginning of script
list
Posts: 137
Joined: 26 Mar 2014, 14:03
Contact:

Re: Remapping Esc key to discard a popup

28 Nov 2018, 18:04

TypingAid will learn words (if I understood it correctly)
typingaid wrote:The script will learn words as you type them if "Learn new words as you type" is set to On in Settings. If you type a word more than 5 times (or as defined in "Minimum length of word to learn") in a single session the word will be permanently added to the list of learned words. Learned words will always appear below predefined words, but will be ranked and ordered among other learned words based on the frequency you type them.
pdecrocq
Posts: 11
Joined: 26 Nov 2018, 03:04

Re: Remapping Esc key to discard a popup

30 Nov 2018, 05:38

Thanks for advice.
Actually the issue is solved since the PE editor improved the popup to have Esc dismiss the dialog.
However, I'm frustrated not to know how to do this using AHK.
Thanks all !

Return to “Ask For Help”

Who is online

Users browsing this forum: frd and 137 guests