AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

key remapping and modifiers

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Torrent
Guest





PostPosted: Mon Jul 12, 2004 7:38 am    Post subject: key remapping and modifiers Reply with quote

I found about autohotkey yesterday and it seems that is just what I was looking for to remap keys in a game. However, I ran into a bit of trouble:

* some keys that I want to remap are letters, so it screws up the chat after a remap. The only way I found so far to enable/disable remapping with a hotkey is to create a state variable that I check in each key remap, so that it returns the proper key if state=0 and the remap if state=1.
- isn't there a better way to do this? It's 6 lines to remap a single key
- if not, what is the command that returns exactly the user's input? (when the hotkey is triggered with say space & a, it seems I can only return space, then a)

sample:
Code:

$r::
if state=1
  Send u
else
  Send r
Return


* the keys I want to remap have different meanings if you have Ctrl, Alt or Shift pressed, but when I remap one, the modifiers have no effect: let's say I remap "r" to "u", "u" is then equivalent to "r" but "Ctrl+u" has the same effect as "u". Question is: should I also remap all modifiers+key?
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Jul 12, 2004 1:04 pm    Post subject: Reply with quote

Quote:
some keys that I want to remap are letters, so it screws up the chat after a remap

If you haven't already, you might try using the tilde modifier to make the keystrokes pass through into the game. Whether this will work as desired depends on what the game does with the R key:
~r::Send u ; This will allow the r to pass through into the game.

Another option is the suspend command, which temporarily disables all hotkeys except those whose first line is Suspend. You could suspend the hotkeys while typing and turn them back on afterward. You could also have a hotkey assigned to it:
#s::Suspend

If you really wanted to get fancy, you might be able to use PixelSearch or PixelGetColor in conjunction with SetTimer and Suspend to automatically detect when the game is in chat mode (if it's possible). Or better still: remap the chat key so that it also turns off the hotkeys while chat is in effect. This example assumes Enter is the chat key and the key to finish the chat, thus enter will turn off the hotkeys while your conversing, and turn them on again afterward.
~Enter::Suspend

Quote:
when the hotkey is triggered with say space & a, it seems I can only return space, then a

If this isn't already solved by the above, you can also use the tilde modifier with these keys if you don't mind the keystrokes passing through into the game:
~space & ~a::MsgBox Both space and a will pass through into the game.
(You can also use the tilde on just one of the above keys if you prefer)

Quote:
Question is: should I also remap all modifiers+key?

You can use the asterisk modifier to remap all variations of a given key:
~*r::send u
However, in your case I don't think this will work because all variations will send a naked letter a rather than a modified letter a. So the solution is to remap all variations that the game uses:
~r::send u
~^r::send ^u
etc.
Back to top
View user's profile Send private message Send e-mail
Pallie



Joined: 05 Jul 2004
Posts: 57
Location: London

PostPosted: Mon Jul 12, 2004 3:12 pm    Post subject: Reply with quote

There is a variable A_ThisHotkey which is the last hotkey pressed. Maybe you could use this to simplify things

Code:
$r::
replacement = u
gosub, replace
return

replace:
if state = 1
  send &A_ThisHotkey&
else
  send replacement
Return

(four lines for each key)
or
Code:
state = 0.

$r::gosub, replace
$q::gosub, replace

replace:
; get rid of any $ prefix
stringreplace, Hotkey, A_ThisHotkey,  $, ,all
if state = 1
; send original keystrokes
  send %Hotkey%
if state = 0
{
  ifequal, Hotkey, r, send, u
  ifequal, Hotkey, q, send, b
}


This way you just need 2 lines for each key (one to rsay you want to redefine the key and one to say what to map it to) and it seems to send the original keypresses back with ^c etc (I've not tried it with things like $space and R)

Mike
Back to top
View user's profile Send private message
Torrent
Guest





PostPosted: Mon Jul 12, 2004 9:04 pm    Post subject: Reply with quote

Thanks guys for the fast replies

The "~" is no good since the remapped keys often have some predefined action so I would end up doing 1 unwanted thing when pressing the key.
I already tried the asterisk before I posted but it didn't work

BUT the Suspend function works like a charm, it allows me to write only one line for each hotkey, and I even managed to play a sound when the script enters/ends Suspend mode Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group