AutoHotkey Community

It is currently May 27th, 2012, 10:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: June 29th, 2007, 1:49 am 
Offline

Joined: June 29th, 2007, 1:06 am
Posts: 4
Howdy,

Could any of you AutoKey cowpersons set me on the trail, I doggone got my nether regions tangled in some loose barbed wire.

I've not been able to fathom a way to create two key stroke hotekys that work like the old WordStar word processor keyboard worked (Whooee! does that mark my days on behind a keyboard).


While the control key is pressed down, I wish to define any number of a two letter combinations as hotkeys. I was hoping something simple like these would work for example:

^k & ^l:: {...}

Ctrl & k & l:: {...}

.... but they produce a syntax error even though the docs imply this should be possible. If you are familiar with the Keyboard mapper in Microsoft Office, it lets you do this and defines them as Ctrl-K, Ctrl-L.

One might depict this as follows:

While (Control is pressed down), detect any of the following L-key combinations
L then D:: send Ctrl-Right
L then A:: send Ctrl-Left
L then R:: send Home
(ad nauseum)
EndWhile

One might do the same with the K key.

BTW, for years I have used a keyboard macro program written in Win 3.1 days called Bridge Batch. Unfortunately Vista seems to have finally laid it to a well deserved rest out in the pucker brush. I think Autokey is my best hope for replacing it.

Thanks very much for any assistanc you can give,
Kenton


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 29th, 2007, 1:52 am 
I read it all but at the end I lost the one thing you are posting for


Report this post
Top
  
Reply with quote  
PostPosted: June 29th, 2007, 3:04 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Kenton wrote:
While the control key is pressed down, I wish to define any number of a two letter combinations as hotkeys.

Perhaps you could adapt this script, which is for "Ctrl+Shift+Alt+2 digit number" hotkeys.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2007, 3:08 am 
Offline

Joined: June 29th, 2007, 1:06 am
Posts: 4
Thank you both for you replies. Sorry if I was confusing, comes from giving up on the caffeine and being way past bed time. I did see the script you mentioned, lexikos, and when a free moment arises I will see if I can adapt it. The first time I took a gander at it it did not look like it as going to do it. However, it might just have the part I need. If it does, AHK might be well on its way to replacing the other tools I use. One item that would be missing, is the ability to save binary data form the clipboard and assoicate it with a hotkey. Great for creating a Library fo stuff from the clipboard. Macro Toolworks, (www.pitrinec.com), has this feature. Something to think about.

Best,
Kenton


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2007, 3:27 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The difficulty is to keep the application-defined Ctrl-digit shortcuts intact. E.g. in Ms Word Ctrl-0 changes the format of the current paragraph. We cannot keep them unchanged, because at seeing Ctrl-0 we don't know if a new digit would follow, so we have to wait. If next the Ctrl key is released, we see that it was not a Ctrl-07 type hotkey, so at this point we can send Ctrl-0 shortcut to the application. That is, the action is performed at the release of the Ctrl-key.
Code:
#UseHook
Loop 10
   HotKey % "^" . A_Index-1, hotty
RETURN

hotty:
   If (digit1 = "")
       digit1 := SubStr(A_ThisHotKey,0) ; last char of hotkey
   Else {
       num := digit1 . SubStr(A_ThisHotKey,0)
       If (num = 00)
           MsgBox 1st command (00)
       Else If (num = 99)
           MsgBox last command (99)
       Else
           MsgBox command (%num%)
       digit1 =
   }
Return

~Ctrl Up::
   IfEqual digit1,,Return ; No Ctrl-digit action pending
   SendInput ^%digit1%
   digit1 =
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 6th, 2007, 12:06 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Laszlo wrote:
The difficulty is to keep the application-defined Ctrl-digit shortcuts intact.
Right you are. That seems to work well, but I think Kenton was after Ctrl+Letters. :)
Code:
Loop, 26    ; 97=a, A_Index starts at 1, so add 96
   HotKey % "^" . Chr(96+A_Index), hotty

You can adjust the starting point (96) and count (26) to include other characters, if need be. Alternatively, you could specify a string of characters to use:
Code:
; you could add a delimiter if you wanted key names (BS,Esc,Home,etc.)
; but you'd also have to change how the keys/digits are collected (in "num")
hotkeychars = adklr
Loop, Parse, hotkeychars  ; for each character in hotkeychars
   HotKey, ^%A_LoopField%, hotty


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 6th, 2007, 1:37 am 
Offline

Joined: June 29th, 2007, 1:06 am
Posts: 4
Hey Guys,

Thanks for the input on this. Your exmaples and discussion helped me flush it out. So, I think I've got it working by dynamically remapping the keys.

Let me backup before delivering the script. When I first did this in Windows 10 years ago in Windows 3.1 (Oh Gawd! Can it really be?! :shock: - show 'n awe man), well I used a tool called Bridge Batch, made by a company now long out of business. At the time it cost $300 or so! Yee eee Ouch, man!. I protest too much, my employer purchased it. Anyway, despite the fact that it is 16bit the Win Hooks API has remained compatible. Somewhat amazing, wouldn't you say ay! There were quirks mind you and some 32 bit programs refused to obey.

So what exactly am I doing. I mentioned that this idea came from the WordStar word processor keyboard (and they may have got it somewhere else for all I could know). In the far off DOS days I used an editor written in assembler called QEdit. Man was that guy fast! Well QEdit used the WordStar keyboard. The primary objective of this keyboard was to allow you to edit withoug ever having to remove your hand from the home row. To do this comfoortably it is first necessary to have the Ctrl key on the home row as it was in wonderful days of yore.

You will notice the little diamond formed by the keys E, D, X, S. In WS key land you held down Ctrl, having to release it would totally ruin the effect - it must act just like the shift key - while pressing these keys to move the cursor around, for example:

Ctrl-E = Up
Ctrl-D = Right
Ctrl-X = Down
Ctrl-S = Left

Lovely, ay, what! With your left hand never leaving the comfort of home, you can move all around. But that is just the start of course. There are more functions that you can accomodate by just using one key. So the next step would be to combine two keys and make them mean something. For example, still holding down Ctrl, again, never having to release it to release the keys, you would type:
Ctrl-KL= Select from cursor to EOL
Ctrl-KK = Cut (it would send a Ctrl-X )
Ctrl-KO = Cut

And so on and so forth etc, etc. Now frankly, I have modified there combinations quite a bit so that left and right hands alternate more, because this seemed to be faster at the time for instance:

Ctrl-LS = Start of Line
Ctrl-LD = End of Line

The beauty of this, you might notice, is that S was Left and D was right so in a way the two keystroke combination has just made the movement bigger. Right well that's enough of that. The second objctive was to be able to use this *reallly wonderful* editing technique in all my windows programs when I switched to Windows. So no matter what app., you are in and in spite of any of its quirks, you can bend it to you will. What I would do was have a hotkey to load a program say Ctrl-2 for Outlook, and at the same time load the hotkey map for Outlook. This was a bit of a pain because you had to remember to do that. Later using Macro Toolworks, which used window hooks to watch the interface, I was able to load my hotkeys auto-magically. BOY! Is this NERDY! I forgot how WHACKED :roll: this really is. OK, OK, the script already:

Code:
 /*
_____________________________________________________________________________________________________
Name:
   Edit-From-Home-Row-Mania

Purpose:
   Creates Ye Olde WordStar Keyboard effect. Why?
   1) Everything in Home Row: By using the Ctrl key, all editing can be done from the home row -
      a boon especially for horrid laptop keyboards   
   2) Common Key Interface: Key actions can be made the same accross all applications

Created:
   KHensley Th.20070705.12:39: proof of concept (incomplete)

Updates:

Notes:
   ? Goto only appears to work forward, is that right?

____________________________________________________________________________________________________
*/

; ...Er, um, forgive the Goto's - it just kind of works in this case. The are used consistently

#SingleInstance Force
#UseHook On

;Capslock::Ctrl
;LAlt::Capslock
LBL_Main:
   Gosub LBL_Main_KeyMap    ;define the base hotkeys
Gosub LBL_ScriptEnd


;******************************
;Key Actions
;******************************

LBL_Left:
   SendInput {Left}
Return

LBL_Right:
   SendInput {Right}
Return

LBL_Delete:
   SendInput {Delete}
Return

LBL_StartOfLine:
   SendInput !{Home}
   Sleep, 500
Goto LBL_Main_KeyMap


LBL_EndOfLine:
   SendInput !{End}
   Sleep, 500
Goto LBL_Main_KeyMap


LBL_SelectFromCursorToEOL:
   SendInput +{End}
   Hotkey, ^l, LBL_L_KeyMap
   Sleep 500
Goto LBL_Main_KeyMap


LBL_GotoLineNumber:
   SendInput ^{g}
   Sleep 500
Goto LBL_Main_KeyMap

LBL_CopySelection:
    SendInput ^{c}
   Sleep 500
Goto LBL_Main_KeyMap


LBL_CutSelection:
    SendInput ^{x}
   Hotkey ^k, LBL_K_KeyMap
   Sleep 500
Goto LBL_Main_KeyMap

LBL_Insert:
   SendInput ^{v}
   Sleep 500
Goto LBL_Main_KeyMap


;******************************
;Hotkey Maps
;******************************

LBL_Main_KeyMap:

   ;The following hotkeys, and their associated procedures will act to create a two keystroke hotkey effect
   ;that stays active while the Ctrl key is held down constantly.

   
   ;^k::Goto LBL_K_KeyMap
   ;Hotkey, ^k, LBL_K_KeyMap
   ;Hotkey, ^k, Off, UseErrorLevel
   ;Hotkey, ^l, Off   , UseErrorLevel
   
   ;Hotkey, ^l, LBL_L_KeyMap   ; ... this doesn't work ???

    Hotkey ^s, LBL_Left      ; cursor left
   Hotkey, ^d, LBL_Right   ; cursor right
   Hotkey, ^g, LBL_Delete   ; delete
   ;^s::Send {Left}
   ;^d::Send {Right}            ; cursor right
   ^e::SendInput {Up}            ; cursor up
   ^x::SendInput {Down}         ; cursor down
    ^a::SendInput ^{Left}         ; word left
   ^f::SendInput ^{Right}         ; word right
   ^r::SendInput {PgUp}         ; page up
   ^c::SendInput {PgDn}         ; page down
   ^i::SendInput {Tab}            ; tab in
   ^o::SendInput +{Tab}         ; tab out
   ^h::SendInput {BackSpace}      ; backspace
   ^t::SendInput +{End}{Delete}   ; delete from cursor to end of line
   

   ;Hotkey, ^l, Off
   ;Hotkey, ^k, Off
   ;Hotkey, ^l, On
   ;HotKey, ^k On
   
   ;^Hotkey, ^k, LBL_K_KeyMap
   ;^Hotkey, ^l, LBL_L_Keymap

   
   ^l::Gosub LBL_L_KeyMap   ;this works but ...
   ^k::GoSub LBL_K_KeyMap

   ;^k::Gosub LBL_K_KeyMap   ;   
   
Goto LBL_ScriptEnd   
;Return ;End Main_KeyMap


LBL_K_KeyMap:

   ;Purpose:
   ;   Remaps keys when the Ctrl-K is pressed
   ;   The "K" keys are generally used for selecting text and operating on it (cut, paste, etc)
   ;Hotkey, ^l, Off

   Hotkey, ^l, LBL_SelectFromCursorToEOL
   Hotkey, ^i, LBL_Insert
   Hotkey, ^o, LBL_CopySelection
   Hotkey, ^k, LBL_CutSelection
Return ;End K_KeyMap


LBL_L_KeyMap:
   ;Purpose: Remaps keys when Ctrl-L is pressed
   ;The "L" keys generaly used for moving the cursor around a document
    Hotkey, ^s, LBL_StartOfLine
    Hotkey, ^d, LBL_EndOfLine
   HotKey, ^g, LBL_GotoLineNumber
Return ;End L_KeyMap


LBL_ScriptEnd:



Yeah, yeah, I know lot's of Gotos. I don't know if there is another way of doing this with AHK and that is where you expers will come in. This script works for for SciTE and all that remains now is to figure out how to load a new set of keys for each app. Well, that and finishing all the scripts for the 15 or so apps that I've written them for.

It took me sometime to figure out how to get it all to work in AHK. With some of the configurations in the procedures, there was some really strange behavior, where the hotkeys would just stop working. It seemed to depend on where I put the remap commands with HotKey.

I would count your opinions most valuable. I have been happily editing this with the aid of AHK and except for the fact that this text box uses the standard Ctrl-End to go to the end of a line and SciTE uses a non-standard Alt-End therefor rendering my Ctrl-KD unusable at the present, I'm a happy man. You AHK developer-type guys really ROCK man!

Thanks,
Kenton[/code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 6th, 2007, 8:48 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Quote:
I have been happily editing this with the aid of AHK and except for the fact that this text box uses the standard Ctrl-End to go to the end of a line and SciTE uses a non-standard Alt-End therefor rendering my Ctrl-KD unusable at the present, I'm a happy man.
:?:
Ctrl+Home/End are "goto beginning/end of document" in most Windows apps...

To make it context sensitive, you could replace
Code:
SendInput !{End}
with
Code:
ifWinActive, ahk_class SciTEWindow
    SendInput !{End}
else
    SendInput ^{End}
or whichever keypresses it is you need.

Also, you can use SendMode to make Send synonymous with SendInput, rather than typing SendInput every time. :)
Code:
SendMode, Input  ; at the start of the script
ahk help: SendMode wrote:
Makes Send synonymous with SendInput or SendPlay rather than the default (SendEvent).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2007, 3:24 am 
Offline

Joined: June 29th, 2007, 1:06 am
Posts: 4
Quote:
Ctrl+Home/End are "goto beginning/end of document" in most Windows apps...


Dead right lexikos! Confusing myself there a wee bit. Too much jubilation, I fathom. It seems though in SciTE that Home/Alt-Home and End/Alt-End do the same thing.

Good tip on the finger saving SendMode. I'll do that!

[bold]Question for you [/bold]. On making this context sensitive for applications, my thought would to find a way to load and unload a particular script for each application. Using conditionals in the script would just get too messy and the files a mite large. Anyway do you know of a way to dynamically load and unload a script from AHK.

Thanks,
Kenton


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 30th, 2007, 7:48 pm 
Offline

Joined: August 23rd, 2005, 7:41 am
Posts: 18
Kenton wrote:
I've not been able to fathom a way to create two key stroke hotekys that work like the old WordStar word processor keyboard worked


OK, I'm coming at this a couple of months late, but I posted about this just about exactly two years ago. Take a look at http://www.autohotkey.com/forum/topic5023.html for my solution. I've been running this script for a couple of years now and it works like a champ.

Kaiwen


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 29th, 2008, 8:33 pm 
Offline

Joined: June 8th, 2008, 11:50 pm
Posts: 9
Location: Spain - Madrid
Kaiwen wrote:

OK, I'm coming at this a couple of months late, but I posted about this just about exactly two years ago. Take a look at http://www.autohotkey.com/forum/topic5023.html for my solution. I've been running this script for a couple of years now and it works like a champ.

Kaiwen


I've visited the topic, as I was (and am) also looking for WordStar navigation emulation and I've seen an excerpt of your script.

Although I understand the idea and I think I could do it from it, it would be a duplicated effort if you wouldn't mind sharing the whole script, or, at least, the WordStar movement part.

Thanks a lot.

_________________
Regards.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, robotkoer and 68 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