Update: I had needed advice on how to implement the key filtering I wanted, but I have since figured it out. I added hot keys for q, w, e and r to the script. This post should either be deleted or moved to the "Scripts and Functions" forum area or the "Gaming Scripts" forum area, which ever is more appropriate. Thanks.
I play a flash game on a website that displays both the game, and a chat. The game uses certain letters on the keyboard (q,w,e,r) as hotkeys.
If the chat does not have focus from the mouse clicking on it:
A: Would it be possible to halt all keyboard key presses?
B: Would it be possible to filter out specific keyboard keys (q,w,e,r)?
When say 'filter' I mean to stop the keys presses from going through. Unintentionally using the hotkeys while the game has focus expends resources. I want the key presses that occur when the chat does not have focus to result in nothingness; for the key presses to disappear in to the ether.
I have written a script that determines if the chat has focus by #1 ImageSearch to find the chat on the page and then #2 detect LButton presses that occur within the chat area. When chat focus is confirmed the variable ChatActive = 1, when chat does not have focus ChatActive = 0.
Images for this script can be downloaded from this link:
https://mega.nz/#F!0...33aBiRxGQfH4-qg
#singleinstance force #usehook On FilterStatus = Inactive ChatStatus = Inactive ChatActive = 0 ChatFound = 0 ; I had wanted to change the background color of the ; button and text label, but reading through the AHK ; Forum there seems to be no simple way to change color. ; That is why I have used images to depict status changes. Gui, Add, Picture, x0 y0 w100 h30 gFilterConfig vpicFilterConfig, Images\Filter%FilterStatus%.png Gui, Add, Picture, x0 y30 w100 h30 vpicChatConfig, Images\Chat%ChatStatus%.png ;Gui, Font, Bold ;Gui, Add, Button, x0 y0 w100 h30 gFilterConfig vbtnFilterStatus, Filter Inactive ;Gui, Add, Text, x0 y38 w100 h30 vlblChatStatus +Center, Chat Inactive Gui, +AlwaysOnTop Gui, Show, x1511 y228 w100 h60, ChatFilter Return FilterConfig: { ; Detect clicks on the Filter image (button) and update accordingly If FilterStatus = Inactive { FilterStatus = Active } Else If FilterStatus = Active { FilterStatus = Inactive GuiControl,, picChatConfig, Images\ChatInactive.png } GuiControl,, picFilterConfig, Images\Filter%FilterStatus%.png } Return ~LButton:: { ChatActive = 0 ; If the Filter is active... ; Search for the Chat Box on the webpage I am using If FilterStatus = Active { If ChatFound = 0 { ; If the Chat Box is found, set the ; perimeter coordinates of the Chat Box ImageSearch, ChatBoxX, ChatBoxY, 0, 0, A_ScreenWidth, A_ScreenHeight, *0 *TransFFFFFF Images\ChatBox.png if ErrorLevel = 0 { ChatFound = 1 ChatBoxL := ChatBoxX ChatBoxT := ChatBoxY ChatBoxR := ChatBoxX + 286 ChatBoxB := ChatBoxY + 42 } Else { ChatFound = 0 ChatActive = 0 } } ; If the Chat Box has been found, determine if ; the mouse has clicked inside of the Chat Box If ChatFound = 1 { MouseGetPos, MouseX, MouseY If (ChatBoxL < MouseX && MouseX < ChatBoxR && ChatBoxT < MouseY && MouseY < ChatBoxB) { ChatActive = 1 } Else { ChatActive = 0 } } GoSub, ChatConfig } } Return ; Update the text label that displays ; whether the user is or is not in chat ChatConfig: { If ChatActive = 1 { ChatStatus = Active } Else If ChatActive = 0 { ChatStatus = Inactive } GuiControl,, picChatConfig, Images\Chat%ChatStatus%.png } Return q:: { If (ChatActive = 1 || FilterStatus = "Inactive") { Send {%A_ThisHotkey%} } } Return w:: { If (ChatActive = 1 || FilterStatus = "Inactive") { Send {%A_ThisHotkey%} } } Return e:: { If (ChatActive = 1 || FilterStatus = "Inactive") { Send {%A_ThisHotkey%} } } Return r:: { If (ChatActive = 1 || FilterStatus = "Inactive") { Send {%A_ThisHotkey%} } } Return GuiClose: ExitApp