Page 1 of 1
Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 01:09
by hasantr
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
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 06:02
by hasantr
In short, I do not want to write letter using this command. But he writes. I have to delete it with backspace.
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 06:59
by MannyKSoSo
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.
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 07:50
by hasantr
Thank you. Everything is so easy.
There is a problem. "V:Visible" I can not write anything without .
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 07:55
by MannyKSoSo
What are you trying to write with the Visible option?
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 13:57
by hasantr
MannyKSoSo wrote:What are you trying to write with the Visible option?
Anything.
and then my keyboard does not work anymore.
There is no problem using the V: option, but then it sends the printed key.
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 14:08
by MannyKSoSo
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.
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 15:15
by hasantr
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
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 15:29
by hasantr
Can I check if the cursor is in the text field?
if(cursorOnTextArea)
{
Send,"Ahk Ahk Ahk..."
}
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 13 Jul 2018, 17:00
by MannyKSoSo
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.
Re: Prevent the Shortcut from Writing to the Text Field.
Posted: 14 Jul 2018, 18:01
by hasantr
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.