How to detect the key that was pressed before Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

How to detect the key that was pressed before

17 Dec 2017, 07:29

Hi there!

I just new in Website deverlope. Each time I use {F12} key or Ctrl+Shirt+C to check the source element, I have the habit that to close the element with ESC key.
So I created

Code: Select all

#IfWinActive, Chrome
~Esc::
Send, {F12}
return
#If
It works, but it just do F12 unexpected sometime.
How can I dectect the F12 or Ctrl+Shift+C has pressed before.
I heard about KeyHistory but don't know how to work with it.
Let get me out of this!

Thanks in advanced! <3
User avatar
boiler
Posts: 17039
Joined: 21 Dec 2014, 02:44

Re: How to detect the key that was pressed before

17 Dec 2017, 09:35

How about just blocking the Esc key when in Chrome?

Code: Select all

#IfWinActive, Chrome
Esc::return
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to detect the key that was pressed before

17 Dec 2017, 13:50

Have you tried checking the built-in variables A_PriorHotkey and A_PriorKey?
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

18 Dec 2017, 14:28

boiler wrote:How about just blocking the Esc key when in Chrome?

Code: Select all

#IfWinActive, Chrome
Esc::return
Thank boiler, I just want to use this on Chrome.
Osprey wrote:Have you tried checking the built-in variables A_PriorHotkey and A_PriorKey?
Thank Osprey, How can I work with it? I am newbie in AHK and very low on English
User avatar
boiler
Posts: 17039
Joined: 21 Dec 2014, 02:44

Re: How to detect the key that was pressed before

18 Dec 2017, 15:19

congdantoancau wrote:
boiler wrote:How about just blocking the Esc key when in Chrome?

Code: Select all

#IfWinActive, Chrome
Esc::return
Thank boiler, I just want to use this on Chrome.
Yes, that's the point. In Chrome, this would prevent you from accidentally pressing Esc and closing the developer tools pane. Isn't that what you wanted?
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

19 Dec 2017, 11:00

boiler wrote: Yes, that's the point. In Chrome, this would prevent you from accidentally pressing Esc and closing the developer tools pane. Isn't that what you wanted?
Yes, I exactly want to close the developer panel with the ESC key. How can I do it?
User avatar
boiler
Posts: 17039
Joined: 21 Dec 2014, 02:44

Re: How to detect the key that was pressed before

19 Dec 2017, 11:12

I misunderstood what you meant. I thought accidentally pressing Esc was messing you up, but now I see you want it to act as the F12 key when in Chrome.

What's the reason for the "~" before the "Esc"? You don't want Esc to perform its normal function, do you? When you do, both the Esc and F12 keys are sent. You just want it to behave like the F12 key, right?

Try simply remapping it like this:

Code: Select all

#IfWinActive, Chrome
Esc::F12
#If
Or alternatively, use the hotkey like you did, but without the "~":

Code: Select all

#IfWinActive, Chrome
Esc::Send, {F12}
#If
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

19 Dec 2017, 11:20

boiler wrote: What's the reason for the "~" before the "Esc"? You don't want Esc to perform its normal function, do you?
Thanks for your response!
No, I don't want the Esc to miss its normal function. I just want the AHK to detect if I am opening the developer panel on Chrome, so just press Esc to close the panel.
When I don't open the panel, Esc must do its normal function like close the save box, finder box, or escape the fullscreen mode or something like that.
At present, I have to do that work (close the developer panel) with F12 key or Ctrl+Shift+I
User avatar
boiler
Posts: 17039
Joined: 21 Dec 2014, 02:44

Re: How to detect the key that was pressed before

19 Dec 2017, 11:37

You could have an #If directive that would only make the hotkey active when both Chrome is active and the developer panel is open by doing an Image Search for something in it like one of the icons in the upper left of that panel. Your #If would then be:
#if DeveloperToolsOpen()

And you would have a function called DeveloperToolsOpen() that would check to see if Chrome is active and if the panel is open by doing the ImageSearch. The function would then return true or false (or 1 or 0).
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

19 Dec 2017, 11:54

boiler wrote:
And you would have a function called DeveloperToolsOpen() that would check to see if Chrome is active and if the panel is open by doing the ImageSearch.
Do you mean I have to search "DeveloperToolsOpen" key word on http://images.google.com ? I did but nothing was find
I added "#If DeveloperToolsOpen()" to my script but it show up error.
Please make it more clearly. Thanks!
User avatar
boiler
Posts: 17039
Joined: 21 Dec 2014, 02:44

Re: How to detect the key that was pressed before  Topic is solved

19 Dec 2017, 12:04

No, I mean you write a function called DeveloperToolsOpen() as part of your script, and that function would check for two things:
1. Whether the active window is Chrome.
2. If the developer tools pane is open. The way it would do that is to use the ImageSearch command to see if it finds the icon, of which you would make a reference .png image by capturing that part of the screen.

It would look something like this:

Code: Select all

DeveloperToolsOpen()
{
	IfWinNotActive, Chrome
		return 0 ; since Chrome is not the  active window, we can return "false" or 0
	ImageSearch,,, 0, 0, A_ScreenWidth, A_ScreenHeight, MyIconImage.png
	return !ErrorLevel ; will return 1 if it's found (not 0) or 0 if it's not (not 1)
}
User avatar
divanebaba
Posts: 807
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: How to detect the key that was pressed before

19 Dec 2017, 12:12

EDIT: Code completely not correct. Theory is ok, I think :crazy:
You don't need to check, which buttons or keys were pressed before, to determine the existence of source window in chrome.
Better way is to direcly check the existence of source window.
With Window Spy the ClassNN is Chrome_RenderWidgetHostHWND1 for nonexisting source window.
Otherwise, there is another ClassNN named Chrome_RenderWidgetHostHWND2, when source window exist.

Code: Select all

if WinExist("ahk_class Chrome_RenderWidgetHostHWND2")
will give you accurate answer.
EDIT: Code completely not correct. :crazy:
Last edited by divanebaba on 19 Dec 2017, 13:46, edited 4 times in total.
Einfach nur ein toller Typ. :mrgreen:
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

19 Dec 2017, 12:40

Thanks, Now I understand.

It kind of hard.

How about searching for texts in the chrome screen without coordinate instead of images. Because the chrome windows can be change the size.
User avatar
boiler
Posts: 17039
Joined: 21 Dec 2014, 02:44

Re: How to detect the key that was pressed before

19 Dec 2017, 12:46

divanebaba showed you how you can tell if it's open without doing an image search.
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

19 Dec 2017, 12:47

divanebaba wrote:You don't need to check, which buttons or keys were pressed before, to determine the existence of source window in chrome.
Better way is to direcly check the existence of source window.
With Window Spy the ClassNN is Chrome_RenderWidgetHostHWND1 for nonexisting source window.
Otherwise, there is another ClassNN named Chrome_RenderWidgetHostHWND2, when source window exist.

Code: Select all

if WinExist("ahk_class Chrome_RenderWidgetHostHWND2")
will give you accurate answer.
Thanks!
I created below code

Code: Select all

f::
if WinExist("ahk_class Chrome_RenderWidgetHostHWND2")
	MsgBox, yes
else
	MsgBox, no
return
But it shows "no" anywhere although I opened up the developer panel in Chrome.
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

19 Dec 2017, 12:59

I have an idea: Can we search for a key word like "html". If it was find, so, it return true. How can I do this?
User avatar
boiler
Posts: 17039
Joined: 21 Dec 2014, 02:44

Re: How to detect the key that was pressed before

19 Dec 2017, 13:24

congdantoancau wrote: It kind of hard.

How about searching for texts in the chrome screen without coordinate instead of images. Because the chrome windows can be change the size.
How hard is it? I just showed you how to do it. And, no those icons don't change with the size or magnification of the browser window. What you are looking to do can't really be done.
User avatar
divanebaba
Posts: 807
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: How to detect the key that was pressed before

19 Dec 2017, 13:41

Hi.
as I was looking for differences in the two versions of displaying, I found that an opened source window causes another control with classNN like described in my post prior.
My fault was not making difference between control classNN and title classNN.
I looked for solution with acceptable difference to start.
I found this approach:

Code: Select all

settitlematchmode 2
WinGet, OutputVar, ControlList, Google Chrome
This gives me different OutputVar while source window is opened or not. In my case, opened source window causes 10 (ten) different controlnames. One more than without source window. I think this could be an approach for your issue.

OMG. My english is so worse. I hope I have made myself clear.

EDIT: I`ve tested intensively and must say, even this will not help you. Sorry. I can't give you reliable solution. Good Luck.
Einfach nur ein toller Typ. :mrgreen:
congdantoancau
Posts: 32
Joined: 11 Apr 2016, 05:14

Re: How to detect the key that was pressed before

19 Dec 2017, 14:16

divanebaba wrote:Hi

EDIT: I`ve tested intensively and must say, even this will not help you. Sorry. I can't give you reliable solution. Good Luck.

I sincerely appreciate your effort in supporting me. It seem doesn´t work.

The code of boiler are work so. Thank you all!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 327 guests