Prevent the Shortcut from Writing to the Text Field.

Get help with using AutoHotkey and its commands and hotkeys
hasantr
Posts: 90
Joined: 05 Apr 2016, 14:18

Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 01:09

NumLock+Any Number. Sample(NumLock+5) = 2015/

I am sending a text to the text writing field. But I had to use Backspace. Because the shortcut key also writes to the text field. Backspace can cause problems.
How can I handle it? I want a solution to not write the shortcut to the text field instead of Backspace or Ctrl + Z.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.uytu
#SingleInstance Force ; Allow only one running instance of script.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetNumLockState, AlwaysOn

dize := ["2011/","2012/","2013/","2014/","2015/","2016/","2017/","2018/","2009/","2010/"]

YilGir:
KeyWait, NumLock, D
Loop,
{
	Input, ts, L1 V
	if( ts = 0 || ts = 1 || ts = 2 || ts = 3|| ts = 4 || ts = 5|| ts = 6|| ts = 7|| ts = 8|| ts = 9)
	{
		If (GetKeyState("NumLock", "P"))
		{
			if(ts = 0) 
				ts := 10 

			;Send, {Control Down}{z}{Control Up}
			Send, {Backspace}
			SendRaw, % dize[ts]
		}
	}
	Break
}
Goto,YilGir
return
hasantr
Posts: 90
Joined: 05 Apr 2016, 14:18

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 06:02

Code: Select all

Input, ts, L1 V
In short, I do not want to write letter using this command. But he writes. I have to delete it with backspace.
MannyKSoSo
Posts: 271
Joined: 28 Apr 2018, 21:59

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 06:59

You could do this

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.uytu
#SingleInstance Force ; Allow only one running instance of script.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetNumLockState, AlwaysOn

dize := ["2011/","2012/","2013/","2014/","2015/","2016/","2017/","2018/","2009/","2010/"]

NumLock::
Input, ts, L1
if( ts = 0 || ts = 1 || ts = 2 || ts = 3|| ts = 4 || ts = 5|| ts = 6|| ts = 7|| ts = 8|| ts = 9)
{
	If (GetKeyState("NumLock", "P"))
	{
		if(ts = 0) 
			ts := 10 
		;Send, {Control Down}{z}{Control Up}
		SendRaw, % dize[ts]
	}
}
return
Edit:
V: Visible. Normally, the user's input is blocked (hidden from the system). Use this option to have the user's keystrokes sent to the active window.
hasantr
Posts: 90
Joined: 05 Apr 2016, 14:18

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 07:50

Thank you. Everything is so easy.

There is a problem. "V:Visible" I can not write anything without .
MannyKSoSo
Posts: 271
Joined: 28 Apr 2018, 21:59

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 07:55

What are you trying to write with the Visible option?
hasantr
Posts: 90
Joined: 05 Apr 2016, 14:18

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 13:57

MannyKSoSo wrote:What are you trying to write with the Visible option?
Anything.

Code: Select all

Input, ts, L1 
and then my keyboard does not work anymore.

Code: Select all

Input, ts, L1 V
There is no problem using the V: option, but then it sends the printed key.
MannyKSoSo
Posts: 271
Joined: 28 Apr 2018, 21:59

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 14:08

So I think the problem is with the loop and the gosub back to the start of that loop. If you just have it only as a hot key like in my example my keyboard works, then when I want to send that key I just hold it down and hit the number. As I am typing this I have the script running, and when I press and hold the numpad and press 3 I get this 2013/ and can type afterwards. Make sure you are encoding to the right format as well. Personally I use UTF-8-BOM for my scripts.
hasantr
Posts: 90
Joined: 05 Apr 2016, 14:18

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 15:15

MannyKSoSo wrote:So I think the problem is with the loop and the gosub back to the start of that loop. If you just have it only as a hot key like in my example my keyboard works, then when I want to send that key I just hold it down and hit the number. As I am typing this I have the script running, and when I press and hold the numpad and press 3 I get this 2013/ and can type afterwards. Make sure you are encoding to the right format as well. Personally I use UTF-8-BOM for my scripts.
The problem was a numerical mouse. :)
https://support.microsoft.com/en-us/hel ... se-pointer

I turned off the numeric mouse completely.

Thank you. Thanks to your help.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.uytu
#SingleInstance Force ; Allow only one running instance of script.
#NoTrayIcon
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetNumLockState, AlwaysOn

dize := ["2011/","2012/","2013/","2014/","2015/","2016/","2017/","2018/","2009/","2010/"]

NumLock::
Input, ts, L1

             if( ts = 0 || ts = 1 || ts = 2 || ts = 3|| ts = 4 || ts = 5|| ts = 6|| ts = 7|| ts = 8|| ts = 9|| ts = "/")
             {
                          If (GetKeyState("NumLock", "P"))
                          {
                                       ;Send, {Backspace}
                                       Send, % dize[ts]
                                       
                                       if(ts = 0) 
                                                    ts := 10
                                       
                                       if(ts = "/")
                                                    Send, {Home}{Shift Down}{End}{Shift Up}
                          }
             }
return
hasantr
Posts: 90
Joined: 05 Apr 2016, 14:18

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 15:29

Can I check if the cursor is in the text field?

if(cursorOnTextArea)
{
Send,"Ahk Ahk Ahk..."
}
MannyKSoSo
Posts: 271
Joined: 28 Apr 2018, 21:59

Re: Prevent the Shortcut from Writing to the Text Field.

13 Jul 2018, 17:00

You can look up the the focus control https://autohotkey.com/docs/commands/Co ... tFocus.htm specific for ControlGetFocus which you can get a loop for something like this

Code: Select all

ControlGetFocus, OutputVar, Untitled - Notepad
if ErrorLevel
    MsgBox, The target window doesn't exist or none of its controls has input focus.
else
    MsgBox, Control with focus = %OutputVar%
However this doesn't do the specific text field. If its a custom ahk gui its easier to do, but if you are on a website trying to input information then I think (could be wrong) use a ComObject to check if you have a text field focused. Other than that I'm unsure you can know if its in a text field. A possible work around could be a tab through different text field after the first one selected (if there are multiple text fields you need to input information).

Edit: #If MouseIsOver("ahk_class (TextField)") would probably be the best bet looking at it more, but its still a more complex problem knowing if you have your cursor over a text box.
hasantr
Posts: 90
Joined: 05 Apr 2016, 14:18

Re: Prevent the Shortcut from Writing to the Text Field.

14 Jul 2018, 18:01

MannyKSoSo wrote:You can look up the the focus control https://autohotkey.com/docs/commands/Co ... tFocus.htm specific for ControlGetFocus which you can get a loop for something like this

Code: Select all

ControlGetFocus, OutputVar, Untitled - Notepad
if ErrorLevel
    MsgBox, The target window doesn't exist or none of its controls has input focus.
else
    MsgBox, Control with focus = %OutputVar%
However this doesn't do the specific text field. If its a custom ahk gui its easier to do, but if you are on a website trying to input information then I think (could be wrong) use a ComObject to check if you have a text field focused. Other than that I'm unsure you can know if its in a text field. A possible work around could be a tab through different text field after the first one selected (if there are multiple text fields you need to input information).

Edit: #If MouseIsOver("ahk_class (TextField)") would probably be the best bet looking at it more, but its still a more complex problem knowing if you have your cursor over a text box.

It was a little complicated for me.
Thank you for everything.

Return to “Ask For Help”

Who is online

Users browsing this forum: Gibbons, kczx3 and 74 guests