AutoHotkey Community

It is currently May 26th, 2012, 8:55 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: June 24th, 2009, 3:45 pm 
Offline

Joined: October 23rd, 2008, 12:49 am
Posts: 14
I would like to use the CapsLock key as a modifer to j,k,i,m to send Left, Right, Up, Down. I also need this to support modifers like shift, control, and alt (shift for selecting text for example, or shift control to select an entire word.).

I am not having any luck.

I've done this:

Code:
CapsLock & k::Send {right}


but this doesn't support the modifiers.

Any suggestions to do this supporting the standard modifier keys.

(fyi: my ultimate goal is a version of touchcursor that will run on my laptop from and from my USB key.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 4:02 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Are you trying to modify those keys only when CapsLock is on? If so you probably need to use GetKeyState:

Code:
~k::
if GetKeyState("Capslock", "T") ; if CapsLock is on
  Send {RIGHT}
else
  Send k
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 4:51 pm 
Offline

Joined: October 23rd, 2008, 12:49 am
Posts: 14
Actually, I want this to work when CapsLock is held down, not on.

Additionally, I tried your script, and when the caps lock is not "on" then two k's are sent. When CapsLock is ON, then a capital K is sent, but the insert point is to the left of the inserted character.

For my education, and to save me from searching through all the docs, can you explain what the tilda is for prior to the hot key character? (I know I've looked this up once, but I can't remember it. I'll probably find it again before an answer is posted. :? )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 5:02 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
rathkopf wrote:
Additionally, I tried your script, and when the caps lock is not "on" then two k's are sent. When CapsLock is ON, then a capital K is sent, but the insert point is to the left of the inserted character.


That's because of the tilde, it prevents the blocking of the key's native function when the hotkey is pressed. I meant to use $ which prevents the hotkey from triggering itself when it sends k. Since we're looking for the held down state and not the toggle state, this might work:

Code:
$k::
if GetKeyState("Capslock", "P") ; if CapsLock is being held down
  Send {RIGHT}
else
  Send k
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 5:08 pm 
Offline

Joined: October 23rd, 2008, 12:49 am
Posts: 14
Thanks.

Better, but now CapsLock + Shift + k sends lower case k, rather than left arrow + shift which selects text.

Also, the CapsLock status is changing. I want CapsLock to stay off (or better yet, in it's last state).

Also, CapsLock+Shift+Ctrl+k should select the word to the left (like control-shift-left does normally). now it does nothing.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 5:35 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
What about
Code:
#If GetKeyState("CapsLock", "P")

j::Left
k::Right
i::Up
m::Down

#If

?

Edit: Oops. :oops: I thought ahk supported the #If hotkey directive now. Nvm that won't work. :lol:

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 7:38 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
infogulch wrote:
Edit: Oops. :oops: I thought ahk supported the #If hotkey directive now. Nvm that won't work. :lol:

Not quite, but this works
Code:
$~*Capslock::
Gui, 99:+ToolWindow
Gui, 99:Show, x-1 w1 +NoActivate, Capslock Is Down
keywait, Capslock
Gui, 99:Destroy
return

#IfWinExist, Capslock Is Down
   j::Left
   k::Right
   i::Up
   m::Down
#IfWinExist

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 8:39 pm 
Offline

Joined: October 23rd, 2008, 12:49 am
Posts: 14
:D
Excellent. Thank you. When I get the rest of the script fleshed out I'll be sure to post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: PKL?
PostPosted: June 25th, 2009, 11:54 am 
Offline

Joined: May 24th, 2009, 1:23 pm
Posts: 89
Location: Bærum, Norway
I use Farkas Máté's PortableKeyboardLayout for that, and more. Here's part of my pkl.ini file:

Code:
[extend]
; These keys are modified/transposed by holding down the 'extend key' (CapsLock by default):
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Esc + |F1 <> |F2 << |F3 >> |F4 <> |F5 <> |F6 << |F7 >> |F8 <> |F9 <> |F10<> |F11<> |F12<> |
;| Caps | Play | Prev | Next | Stop | Mute | Vol- | Vol+ | Media| BrHom| Mail | App1 | App2 |
;+======+======+======+======+======+======+======+======+======+======+======+======+======+
;|` ¤¤¤ |1     |2     |3     |4     |5     |6     |7     |8     |9     |0     |-     |=     |
;| Del  | F1   | F2   | F3   | F4   | F5   | F6   | F7   | F8   | F9   | F10  | F11  | F12  |
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Tab   |Q <<> |W +++ |F <>> |P *** |G *** |J ### |L ### |U ### |Y ### |; ¤¤¤ |[ ¤¤¤ |] ¤¤¤ |
;|      | BrBck| Win  | BrFwd| *WhUp| *Btn1| PgUp | Home | Up   | End  | Del  | Esc  | Ins  |
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Caps+ |A +++ |R +++ |S +++ |T *** |D *** |H ### |N ### |E ### |I ### |O ¤¤¤ |' ¤¤¤ |\ ><> |
;| ++++ | Alt  | Ctrl | Shift| *WhDn| *Up17| PgDn | Left | Down | Right| Back | Apps | BrFav|
;+------+------+------+------+------+------+------+------+------+------+------+------+------+
;|Z ¤¤¤ |X === |C === |V === |B *** |_ *** |K *** |M *** |, *** |. *** |/ *** |Spc ¤ |Entr¤ |
;| Esc  | Cut  | Copy | Paste| *Le17| *Dn17| *Ri17| *Btn3| *WhLe| *WhRi| *Btn2| Enter| Break|
;+------+------+------+------+------+------+------+------+------+------+------+-------------+
;Legend: # Movement; + Modifiers; = GUI edit; * Mouse; <> MultiMedia; ¤ Various commands.


; NOTES:
; - This map shows a 'comfort' Colemak with VK_102 in the middle (the '_' key). See below.
; - The actual remaps are by scan codes though, so the positions are layout independent!
; - Multiple extending modifiers would've been nice; this setup is a general/basic one.
; - For instance, extended virtual mousing, NumPad/maths, mirror layout, coder's toolbox...
; - If your layout doesn't define the key, 'extend' won't work with it!
;    * Workaround: Put, e.g., 'SC039 = SPACE   VirtualKey' in your layout .ini file.
;    * This will be necessary for Escape/Space/Return/Back and F1-F12 for full functionality.
; - The Tab key is currently a poor candidate for remapping because of problems with AltTab.
;    * It might be useable as another extensor/modifier though?
; - Unfortunately, the WARS (WASD) modifier block only works partially! A bug?
;    * The S=Shift and A=Alt work fairly well, but the R=CtRL is dodgy.
; - Are the "Wheel left/right" keys actual keys or AHK code?

; TIPS:
; - These mappings enable you to do many things without leaving the typing home position.
;    * Mappings are based on ease of reach vs. usefulness, and some left-hand-only use.
; - This could take some getting used to for the left pinky, but then it gets really cool!!!
; - The Caps key plus Esc turns the CapsLock state on and off now.
; - It's handy to control your browser back/forward with the left hand only while browsing.
; - Similarly, the wheel up/down keys are favorites.
; - Caps+Space for Enter is also nice; can be worked with left-hand-only as well.
;    * To press dialogue buttons for instance, use Tab to move and Space/Q to select/abort.
;    * A+Space (=Alt+Enter) when a file/disk is selected, brings up the object's Properties.
; - Use the \ (or *Btn2) for context menus; arrows, 'mousing' or shortcuts select items.
; - An Esc mapped to '[' (Telnet/Vim/etc compliant) is nice, but a left-hand one even better.
; - The left-hand Del key is also convenient; the right-hand one is best when editing.
; - Cut/Copy/Paste are Windows 'keypress' versions - should work mostly anywhere.
;    * I wished to have an Undo key on 'z', but that doesn't exist!?!
; - In theory, using WARS with the UNEI/LY/O' keys you can jump words, jump/select, etc.
;    * Not all these are currently working though, so you may have to use 'real' modifiers.
; - The number keys are mapped to function keys. They are reachable with the left hand!
;    * A4 closes apps; W3 GUI-searches; 1(Help)/2(Rename)/3(Find)/5(Refresh) are useful too.
; - The function keys are mapped to multimedia keys like the ones on multimedia keyboards.
;    * Browser_Stop/Refresh/Search are usually covered by hotkeys (e.g., Esc/F5/^F).
;    * Browser_Favorites usually needs a menu choice, so that's an inclusion candidate.
; - The App1/2 keys are defined in the registry, in a ShellExecute (REG_SZ) value under (?):
;    * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\17
;    * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18
; - Wheel Up/Dn are nice for scrolling window bars; Wheel Left/Right for horizontal scroll.
; - The 'virtual mousing' is rudimentary; a 'last resort' when arrows/Tab aren't enough.
;    * A mousing resolution of 17 pixels roughly fits *most* context and similiar menus.
;    * A full mouse layout would have multi-resolution, diagonals, sticky Btn1 and Btn4/Btn5.
;    * The keyboard's auto-repeat makes virtual mousing odd/'laggy' when a key is held down.
;    * In particular, beware of holding down the *Btn key(s) for a 'rapid-click' effect.


; *** 'ESC'/'SPACE'
SC001 = CapsLock
SC039 = Enter

; *** 'F1'-'F12'
;The F key block holds multimedia keys, Logitech/Mac-style (F1-F4 are easiest to reach)
SC03b = Media_Play_Pause
SC03c = Media_Prev
SC03d = Media_Next
SC03e = Media_Stop
SC03f = Volume_Mute
SC040 = Volume_Down
SC041 = Volume_Up
SC042 = Launch_Media
SC043 = Browser_Home
SC044 = Launch_Mail
SC057 = Launch_App1
SC058 = Launch_App2

; *** Row 1 (numbers/symbols)
SC029 = Del
SC002 = F1
SC003 = F2
SC004 = F3
SC005 = F4
SC006 = F5
SC007 = F6
SC008 = F7
SC009 = F8
SC00a = F9
SC00b = F10
SC00c = F11
SC00d = F12
SC00e = Sleep

; *** Row 2 (upper letter row)
SC00f = Tab
SC010 = Browser_Back
SC011 = Win
SC012 = Browser_Forward
SC013 = WheelUp
SC014 = LButton
SC015 = PgUp
SC016 = Home
SC017 = Up
SC018 = End
SC019 = Del
SC01a = Esc
SC01b = Ins

; *** Row 3 (home row)
;SC03a = CapsLock
SC01e = Alt
SC01f = Ctrl
SC020 = Shift
SC021 = WheelDown
SC022 = Click Rel 0,-17,0
SC023 = PgDn
SC024 = Left
SC025 = Down
SC026 = Right
SC027 = BackSpace
SC028 = AppsKey
SC02b = Browser_Favorites
SC01c = CtrlBreak

; *** Row 4 (lower letter row)
;SC02a = LShift
; ***** SEE THE [EXTRA] SECTION FOR OPTIONAL 'COMFORT' REGISTRY REMAPPING *****
; Non-registry-mapped 'comfort' layout - VK_102 in the lower left corner is used as 'Z'.
SC056 = Esc
SC02c = Cut
SC02d = Copy
SC02e = Paste
SC02f = Click Rel -17,0,0
SC030 = Click Rel 0,17,0
SC031 = Click Rel 17,0,0
SC032 = MButton
; ***** END OF 'COMFORT'/'NON-COMFORT' PART (PASTE BETWEEN THESE LINES) *******
SC033 = WheelLeft
SC034 = WheelRight
SC035 = RButton
;SC036 = RShift


[extra]
; This section is not read by the program, but contains snippets for other sections.

; Mappings for scan code mapped versus unmapped 'comfort' layout (ZXCVB+VK_102 keys)
; (These keys may already be mapped on a lower level than PKL, by registry)
; Copy the appropriate set into your pkl.ini -> [extend] section, row 4.

; Non-registry-mapped 'comfort' layout - VK_102 in the lower left corner is used as 'Z'.
SC056 = Esc
SC02c = Cut
SC02d = Copy
SC02e = Paste
SC02f = Click Rel -17,0,0
SC030 = Click Rel 0,17,0
SC031 = Click Rel 17,0,0
SC032 = MButton

; Non-registry-mapped 'non-comfort' layout - if you have no VK_102 key (or WANT pain?!).
SC02c = Esc
SC02d = Cut
SC02e = Copy
SC02f = Paste
SC030 = Click Rel 0,17,0
SC031 = Click Rel -17,0,0
SC032 = Click Rel 17,0,0
; Instead of a mouse 'cross', there's now up/down and left/right pairs.
; If you want the middle button, you may replace the left-hand Esc (but I wouldn't).

; Scancode/registry mapped 'comfort' layout - VK_102 now sits in the old 'B' position.
SC02c = Esc
SC02d = Cut
SC02e = Copy
SC02f = Paste
SC030 = Click Rel -17,0,0
SC056 = Click Rel 0,17,0
SC031 = Click Rel 17,0,0
SC032 = MButton


I greatly enjoy the power of all that, and it's right there on my USB stick at all times! For instance, to quit an app I'll press CapsLock and then 'A' and '4' for Alt-F4 to quit without leaving home position. Then, arrow keys like yours and the Space bar (for Enter) or 'Z' (for Escape) navigate menus. As you can see, there's a lot more there too.

Note that you'll need a layout which defines all the keys you're planning to 'extend'. The mappings may be a mere pass-through 'VirtualKey'.

_________________
Better burden you cannot carry than man-wisdom much -- Hávamál


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 7:38 am 
Offline

Joined: October 23rd, 2008, 12:49 am
Posts: 14
DreymaR

Thanks for pointing me to PKL.

Now, my next question is, can I map and extended key to press two other keys? I use J and L (actally Dvorak H and S) in TouchCoursor to move back and forward one word, i.e. ctrl-left and ctrl-right.

Can I do this with PortableKeyboardLayout?

thanks.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 1st, 2009, 5:19 pm 
Offline

Joined: October 23rd, 2008, 12:49 am
Posts: 14
I'd also like to Disable the CapsLock key for the CapsLock function, and rather map CapsLock to CapsLock+Tab.

Can this be done with PKL?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 6:14 pm 
Offline

Joined: May 24th, 2009, 1:23 pm
Posts: 89
Location: Bærum, Norway
In theory the two-stroke mapping should be easy enough, but somehow I didn't get it to work in PKL. What I do is press the Ctrl key with the CapsLock. For instance, to select a word backwards I'll press Caps-Ctrl-Shift-'N' (Colemak; that's QWERTY 'J' for the backwards and, uh, 'H' for you). I first tried to make it work with 'R' (QWERTY 'S'; Dvorak 'O') as Ctrl, but that didn't play well with the other kids on the letter block. I think the keyboard itself may be to blame and a non-aliased board might work. I'm using 'A' as Alt and 'S' as Shift with much better results.

I wouldn't use the Tab key because it's very useful as it is (unmapped) and sometimes mapping it will mess with integrated functionality such as Alt-Tabbing. I suggest using Caps+Esc or Caps+'`' instead. That's what I do.

To be sure the full 'extend' layout works and the CapsLock doesn't misbehave, I use the following snippet in the [layout] section of my layout .ini file:
Code:
; *** Using 'CapsLock' as 'extend_key' works best if it is mapped but otherwise disabled
CapsLock = OEM_CAPITAL   0   --   --   --   --   --   ; CapsLock
; *** To make a key work with the 'extend_key' modifier, it needs to be virtual-mapped as below.
; *** When VirtualKey-mapping the BACKSPACE/ENTER keys, use their enumerations BACK/RETURN.
; *** Remapping the TAB key is problematic: Alt-Tab becomes 'sticky', needing Esc to get out.
SC001 = ESCAPE   VirtualKey
SC00e = BACK   VirtualKey
;SC00f = TAB   VirtualKey
SC01c = RETURN   VirtualKey
SC039 = SPACE   VirtualKey
SC03b = F1   VirtualKey
SC03c = F2   VirtualKey
SC03d = F3   VirtualKey
SC03e = F4   VirtualKey
SC03f = F5   VirtualKey
SC040 = F6   VirtualKey
SC041 = F7   VirtualKey
SC042 = F8   VirtualKey
SC043 = F9   VirtualKey
SC044 = F10   VirtualKey
SC057 = F11   VirtualKey
SC058 = F12   VirtualKey

_________________
Better burden you cannot carry than man-wisdom much -- Hávamál


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 6:26 pm 
Offline

Joined: October 23rd, 2008, 12:49 am
Posts: 14
Thanks again. Probably right about the Tab. In my home-grown remapping I had used the escape, so capslock+escape actually toggled the capslock. I'll stick with that.

Bummer on the two-stroke mapping. I didn't get it to work either. I tried ^Left and ^Right, but that didn't do it.

Maybe someone else will shed light on this.

Thanks for your snippit. I'll have to include that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 6:29 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
You can use [VxE]'s method of remapping with two strokes. (make the first key create a hidden gui window). Just name each gui differently and use different gui numbers, and there ya go.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 7:49 pm 
Offline

Joined: May 24th, 2009, 1:23 pm
Posts: 89
Location: Bærum, Norway
Remapping two strokes in AHK is no problem for sure. It's a bit more tricky with Portable Keyboard Layout it seems. Of course, if it matters to you there's always the AHK source code for PKL - so you could do anything you wanted if you want to invest the effort.

_________________
Better burden you cannot carry than man-wisdom much -- Hávamál


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, coinman, oldbrother and 64 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group