(Solved, my bad) Native Key and Defined Hotkey act differently? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nutnutwin
Posts: 76
Joined: 28 Aug 2019, 07:25

(Solved, my bad) Native Key and Defined Hotkey act differently?

Post by nutnutwin » 28 Nov 2021, 21:33

Hi, thank you for reading my question

# What I know
- I can send key using Send/SendInput(which is faster)

# What I did
I have the following code that send 「Home」 when I press Ctrl+Left

Code: Select all

^Left::				SendInput, {Home}
# What I noticed
I thought they(Ctrl+Left, HomeKey) would do the same,
while in Chrome/Edge TextBox
eg. TextBox I am currently using to post a new topic

- Ctrl+Left would simply move to the beginning of line(BOL), and stay there
↑I call this 「Home_Simple」

- Home Key on the keyboard, on the other hand, would
go to the beginning of line, if the line is not empty
go to the beninning of the TextBox(as if Ctrl+Home is pressed instead)
↑I call this 「Home_Fancy」

--- ✄ -----------------------
# What I ask
I understand that going to the beginning of TextBox is a Chrome feature.
but why is there a difference in such case?
I went through the document but found no hint

--- ✄ -----------------------
# Currently I am using
SendInput, +{Home} to select to the BOL, but get messed by Chrome's Feature
(Which end up selecting the whole TextBox)

I wonder if it is possible to just send 「Home_Simple」?
I tried using ^+{Left}, but it is an another function in Chrome (Select left by word)

Thank you for your time.
Last edited by nutnutwin on 28 Nov 2021, 22:09, edited 1 time in total.

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Native Key and Defined Hotkey act differently?

Post by mikeyww » 28 Nov 2021, 21:44

AHK is just doing what would happen if you pressed Home. I'm confused: why would you press Home if the current line contains no text?

nutnutwin
Posts: 76
Joined: 28 Aug 2019, 07:25

Re: Native Key and Defined Hotkey act differently?

Post by nutnutwin » 28 Nov 2021, 21:53

mikeyww wrote:
28 Nov 2021, 21:44
AHK is just doing what would happen if you pressed Home. I'm confused: why would you press Home if the current line contains no text?
OMG I think I made a big mistake...
I don't know why but now Home and Ctrl+Left works the same.


I think you are right, I am sorry


Hi, sorry for being confusing
What I want to do is to,
^j:: SendInput, +{Home}{Backspace}
so that

- if the current line contains no text, Backspace to delete to the previous line
- if the line contain something, delete to the beginning of line(next press will do the ↑)

so if I repeated press Ctrl+J, will "detele to BOL, delete to the previous line, then delete to BOL",
which is convenient for me in most editors.

Here the Chrome Home_Fancy problem kicks in.

--- ✄ -----------------------
as you have said previously "AHK is just doing what would happen if you pressed Home."

from what I tried, pressing Ctrl+Left(which send Home), acts differently from just "Home"

Thank you

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Native Key and Defined Hotkey act differently?  Topic is solved

Post by mikeyww » 28 Nov 2021, 22:02

In my testing, Ctrl+Left does the same as Home, when the script is running. Nonetheless, it looks like you are seeking a script which can actually alter how Home works, or can determine how many characters are on the current line, or whether the current line has no text. I did not actually realize that Home has a special function in Chrome, until you pointed it out. You may want to have a look at Chrome.ahk, or search the forum for posts showing how to retrieve text from, and positioning in, a Chrome form field. I wish I could be more helpful!

nutnutwin
Posts: 76
Joined: 28 Aug 2019, 07:25

Re: Native Key and Defined Hotkey act differently?

Post by nutnutwin » 28 Nov 2021, 23:44

mikeyww wrote:
28 Nov 2021, 22:02
In my testing, Ctrl+Left does the same as Home, when the script is running. Nonetheless, it looks like you are seeking a script which can actually alter how Home works, or can determine how many characters are on the current line, or whether the current line has no text. I did not actually realize that Home has a special function in Chrome, until you pointed it out. You may want to have a look at Chrome.ahk, or search the forum for posts showing how to retrieve text from, and positioning in, a Chrome form field. I wish I could be more helpful!
I miss Firefox, where you get what you pressed.
(which on the other hand works poorly, with many modern Web Apps

another example with Chrome fanciness, is that it take away your "spaces" when you paste.
If you paste "abc "(3 spaces at the end), you get only "abc"(which need extra work to workaround.

--- ✄ -----------------------
will look at Chrome.ahk
https://github.com/G33kDude/Chrome.ahk

> I wish I could be more helpful!
you are more than helpful. Thank you so much.

nutnutwin
Posts: 76
Joined: 28 Aug 2019, 07:25

Re: Native Key and Defined Hotkey act differently?

Post by nutnutwin » 29 Nov 2021, 15:49

mikeyww wrote:
28 Nov 2021, 22:02
In my testing, Ctrl+Left does the same as Home, when the script is running. Nonetheless, it looks like you are seeking a script which can actually alter how Home works, or can determine how many characters are on the current line, or whether the current line has no text. I did not actually realize that Home has a special function in Chrome, until you pointed it out. You may want to have a look at Chrome.ahk, or search the forum for posts showing how to retrieve text from, and positioning in, a Chrome form field. I wish I could be more helpful!
this does the job, but need extra workaround when press ^z
works fine for me now

Code: Select all

	$^j::
			Clip_Save = % ClipboardAll
			SendInput, {Space}+{Home}^{c}		; 💬^{x} is fine, butFlashy

			If (Clipboard = " ")		; is on empty line
				SendInput, {Backspace 2}
			Else
				SendInput, {Backspace}
			Clipboard = % Clip_Save


Post Reply

Return to “Ask for Help (v1)”