Author Topic: some basic help needed on autohotkey and I don't know where to post this thread  (Read 2768 times)

0 Members and 1 Guest are viewing this topic.

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Hello Folks

I need some help taking baby steps on my way to geekdom.

Right now I知 messing with autohotkey for the first time. My only programming experience was getting D- in a college programming class, so you can figure out how good I am at this sort of thing.

I知 trying to remap a few keys that I don稚 use much. I知 also trying to get autohotkey to run a few basic key sequences.

These remapped keys don稚 seem to cause trouble for Autohotkey.
ScrollLock::Run calc.exe
`::PgDn
Esc::PgUp
Pause::Esc
PgDn::^w

All of these guys below are causing problems:

PgUp::Shift3                         I知 trying to get the page up key to do shift 3 instead. In Gmail, shift 3 trashes an email.
Home::^c^t^vEnter               I知 try to get the home key to execute a little routine. To copy a piece of text, open a new chrome window, paste the text and get chrome to search.
End::RButtonDownEnter     I知 trying to get the end key to do a right mouse click, scroll down one step, then enter. It痴 essentially right click mouse and open in a new window.

I知 sure Soarer or some Power Geek will laugh and say he did it in elementary school, but hey, I知 40 years behind this so any advice is good advice!
Most of the modding can be done on your own once you break through the psychological barriers.

Offline Aranair

  • Posts: 215
  • Location: Singapore
  • Software Engineer @ PocketMath
    • Tech blog
mm I think shift is + if i'm not wrong. But does shift 3 really delete an email? mm I just tried and it doesn't seem to work on my gmail lol

Present  : HHKB Pro 2 Type-S White | HHKB Pro 2 White Blank | Ergodox EZ
Past      :  Poker 2 Brown | Black Widow Ultimate Blue | Filco TKL Brown

Offline Aranair

  • Posts: 215
  • Location: Singapore
  • Software Engineer @ PocketMath
    • Tech blog
For the new window, you can try ^n.

(Or if you wanted a new tab its actually ^t)


Guess I misunderstood you on this one. You actually wanted to click on a link where your mouse is on?


For the right click: (change t to w for new window)
Code: [Select]
End::
Send {MButton}
Send {t}
Return


For the copy and paste: (change n to t for new tab)

Code: [Select]
`::
Send, ^c
Send, ^n
Send, ^v
Send {Enter}
Return
« Last Edit: Fri, 14 June 2013, 12:24:41 by Aranair »

Present  : HHKB Pro 2 Type-S White | HHKB Pro 2 White Blank | Ergodox EZ
Past      :  Poker 2 Brown | Black Widow Ultimate Blue | Filco TKL Brown

Offline laffindude

  • Posts: 1521
  • ( ̽ ャ ˳ャ)
All of these guys below are causing problems:

PgUp::Shift3                         I知 trying to get the page up key to do shift 3 instead. In Gmail, shift 3 trashes an email.
Home::^c^t^vEnter               I知 try to get the home key to execute a little routine. To copy a piece of text, open a new chrome window, paste the text and get chrome to search.
End::RButtonDownEnter     I知 trying to get the end key to do a right mouse click, scroll down one step, then enter. It痴 essentially right click mouse and open in a new window.

These are hotkeys, so you need to write them differently. The a::b only works for rebinding.
Shift one requires curly brackets, like :: Send {Shift 3}, or it would interpret it as you want to press all those keys individually. Basically, all the keys names longer than 1 letter require brackets. See the list here: http://www.autohotkey.com/docs/commands/Send.htm

on the routine thing, you should add some delay to make the script more reliable since new tab doesn't always pop up instantly.
Code: [Select]
`::
Send, ^c
Send, ^n
sleep 500 ;500ms sleep
Send, ^v
Send {Enter}
Return

Here is my calculator function. a little smarter:
Code: [Select]
B::
IfWinExist, Calculator ahk_class CalcFrame
{
IfWinActive
WinMinimize
else
WinActivate
}
Else
Run calc.exe
return

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Hey Aranair

thanks for the great help!

I still don't understand how the Send command works, and how {xxx} functions.

But your code works perfectly, so I'm tweaking it and experimenting now.

Another thing I find weird is that holding down shift and then pressing numeric row 3 does work on my gmail. It does not work when you press shift and then numpad 3, regardless of whether numlock is on or off. (Am a weak geek using Windows7, so if you're a power geek on linux I can't speak for you!)

My only grouse... is that because I'm using a buckling spring, I just can't remember what I did to the keys! Wish they made relegendables for buckling springs!  :)) :)) :))
Most of the modding can be done on your own once you break through the psychological barriers.

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
thanks a lot, laffindude

right now it is night where I am and my brain isn't capable of absorbing your new info anymore. But I will investigate your suggestions.

But can I ask you if it is possible to make the scroll lock button toggle a whole layer? I figured that numlock and caps lock shouldn't be messed with too much, but the scroll lock is normally unused. I'm hoping to make it work something like a 'switch profile' key. When I toggle scroll lock and it is on, my keys turn into a certain profile - eg pressing on a numpad key will trigger a macro. When I toggle scroll lock off, all keys return to normal. NUmpad will return to their numbers and home/end/pageupdown functions depending on whether numlock is triggered.

Any suggestions for that?

Thanks again, laffindude and aranair!
Most of the modding can be done on your own once you break through the psychological barriers.

Offline laffindude

  • Posts: 1521
  • ( ̽ ャ ˳ャ)
Sure

Add these in the beginning of your script


Code: [Select]
Suspend, On
SetCapslockState, Off

Then with rest of your binds:
Code: [Select]
ScrollLock Up::
Suspend Off
If GetKeyState("ScrollLock","T")
{
Suspend on
SetScrollLockState, Off
}
Else
{
Suspend off
SetScrollLockState, on
}
return

see if it works

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
whew! I don't understand your script. But I will try it out! (I find Autohotkey's documentation pretty detailed, but because it doesn't explain the logic behind some syntax, I'm in the position of a guy who is given fishes but never learns how to fish.)
Most of the modding can be done on your own once you break through the psychological barriers.

Offline laffindude

  • Posts: 1521
  • ( ̽ ャ ˳ャ)
Suspend will stop the hotkeys from firing. http://www.autohotkey.com/docs/commands/Suspend.htm So I just wrote a simple check for scroll-lock state, then set the suspend status according to the scroll-lock LED. (LED on = binds enabled). Those 2 lines for the autoexec section just initialize the settings. Only the Suspend part is important. The scroll-lock hotkey is only fired on release, so it doesn't keep firing when you hold it down.
GetKeyState() here: http://www.autohotkey.com/docs/Functions.htm#GetKeyState



Edit: PS i just saw what you want to do with the shift3 thinger. try Send +3.
« Last Edit: Sat, 15 June 2013, 06:37:49 by laffindude »

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
 :D :D

Hey Laffindude

Can I ask you how to relabel a key that has upper and lower case functions? You see, I want to exchange backspace with "'. The "' key isn't used that much, but if I exchange it with backspace, I will be able to toggle backspace with my fourth finger more easily.

The "' is moved to backspace, but obviously I will need to retain both " and ' and I cant figure out how to do it...

BTW...

Between you and Aranair's help, I've run out of space on my Model M to turn into hotkeys, shortcuts and macro keys! And since I figured that it's too hard to remember all the key remaps if I use the Scroll Lock to toggle a whole new layer, I think I'll temporarily shelve the scroll lock layer mini project. (Was hoping that Shadovved could sell me stickers so that I can relabel my keys, but turns out he doesn't have the right stickers.)

I have a 122-key terminal that I've never gotten to working on, so I guess the Space UnSaver's gotta come out sooner or later...
Most of the modding can be done on your own once you break through the psychological barriers.

Offline laffindude

  • Posts: 1521
  • ( ̽ ャ ˳ャ)
try
Code: [Select]
*backspace::'
*'::backspace

* = wildcard. It'll fire the hotkey even when modifiers are pressed: http://www.autohotkey.com/docs/Hotkeys.htm find wildcard.



Edit: if it isn't working as intended, you can try blind send mode:
*Backspace::Send {Blind}{Delete} <-- something i grabbed out of my script. Blind mode won't release modifiers you've pressed. Usually shift doesn't need it, but you may need this if you use other modifiers + the bound keys.

PS, you can imagine my AHK script is quite long ;)
« Last Edit: Sat, 15 June 2013, 11:35:54 by laffindude »

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Hello Laffindude!

your backspace rebind worked perfectly, but I found I couldn't get used to it, so I decided to try rebinding the backslash key to backspace instead which I found that I couldn't remap unless I always put a wildcard * in front. EG
*\::backspace

*backspace::
Send ^{LButton}
Return

I don't have a problem doing this. I'm just trying to understand wildcard logic. I have a bunch of other remaps and hotkeys/hotkey combos on my script, and the only things that have given me problems are the backspace and backslash which require wildcards in front. If you hadn't told me about wildcards, I would probably still be stumbling in the dark.

Also have other questions:

When you wrote
Suspend, On
SetCapslockState, Off
did you mean SetScrollLockState, Off since it was ScrollLock that I was messing with?

Also, Now I want to mess with the numpad. Here's what I intend to do:

except for numlock, there are 17 keys on the numpad. I'm thinking of turning them all into macros when numlock is off. After all, their functions (things like home and left arrow) are already replicated in the tenkey area.

When I need to use numpad, I want to be able to just turn on numlock and instantly get back all my regular calculator functions.

However, whether numlock is on or off, I want my other remapped keys and macros to work fine. IE there is a set of 17 macros that only need to work when numlock is off, while other key rebinds and hotkeys etc are not supposed to be affected.

So where do I insert my 17 macros? Is it somewhere inside the text below?

ScrollLock Up::   
   Suspend Off
      If GetKeyState("ScrollLock","T")
      {
         Suspend on
         SetScrollLockState, Off
      }
      Else
      {
         Suspend off
         SetScrollLockState, on
      }
   return

Thanks for all your help so far!
« Last Edit: Mon, 17 June 2013, 08:49:02 by berserkfan »
Most of the modding can be done on your own once you break through the psychological barriers.

Offline laffindude

  • Posts: 1521
  • ( ̽ ャ ˳ャ)
Not entirely sure why you need wildcards sometimes. I use it because it will still fire the hotkeys/binds when I press the modifiers. Blind mode ensure it is sent as intended (for example, fn + backspace = del for me, the way i wrote my script is that I can hit ctrl + alt + fn + backspace to send ctrl+alt+del. Without the blind mode + wildcard, it is not possible.).


Yes @ SetScrollLockState. I was sleepy when I wrote that.


It is a little bit more involved if you want to do the number pad. My scroll lock trick basically turns off all the binds with suspend. It is the easiest way to turn it on and off. I don't think you need it for number lock. First, try to bind the key names with number lock off (see list: http://www.autohotkey.com/docs/KeyList.htm ). See if that works. If it works, it will be the easiest way to get it working. If not, then I guess it is still possible to run a 2nd AHK script just for the numpad region. Doing it all in 1 script will require more complex logic.

17 binds can go before or after that block of code. It doesn't matter. There is only really 2 sections to AHK scripts. autoexec section (basically the top: http://www.autohotkey.com/docs/Scripts.htm#auto ). Other than that, it doesn't really matter what order you have things.

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Hello Aranair and Laffindude

First off I must thank you for all your help!

Do you know any way to make autohotkey identify keyboards and treat them separately? Ie I want a certain layout or remap to work only on one keyboard; on the other I want different settings. Both are connected to the computer at the same time.

I'm hoping to have an array of 2 keyboards at the same time with different uses for the keys.

If it helps, one of the keyboards has a Soarer inside and the other doesn't, so some way of having autohotkey differentiate between the keyboards should go a long way.

thank you for any suggestions and shared experiences!
Most of the modding can be done on your own once you break through the psychological barriers.