Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Accelerator for Right+Numpad?

Accelerator for Right+Numpad?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Kahenraz   (75 posts)  Bio
Date Fri 26 Aug 2016 04:11 PM (UTC)
Message
I'd like to add an accelerator for a combination of the right arrow and numpad directional keys for fleeing from combat so that I can run around fighting stuff with just one hand without having to bring a second one in just to flee.

I tried the following but it did not work:

AcceleratorTo ("Right+Numpad8", "flee north", sendto.world)


I assume the prefix only supports Ctrl/Alt/Shift.
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #1 on Fri 26 Aug 2016 05:11 PM (UTC)
Message
Quote:
I assume the prefix only supports Ctrl/Alt/Shift.

This is a limitation in the operating system. You can't just combine any two keys arbitrarily.

https://en.wikipedia.org/wiki/Modifier_key

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Kahenraz   (75 posts)  Bio
Date Reply #2 on Fri 26 Aug 2016 05:53 PM (UTC)
Message
It's a limitation of the implementation not the operating system.

For example, this can be done with GetKeyState(), GetAsyncKeyState(), or GetKeyboardState().

It sounds like the current implementation uses RegisterHotKey(), which is very limited.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 27 Aug 2016 09:32 PM (UTC)
Message
The function RegisterHotKey is not anywhere in the source.

You can view that at http://www.gammon.com.au//git

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 28 Aug 2016 03:35 AM (UTC)

Amended on Sun 28 Aug 2016 04:02 AM (UTC) by Nick Gammon

Message
You could achieve this with a combination of

GetInfo (294) and AcceleratorTo:

For example:


AcceleratorTo ("Ctrl+Numpad8" , ' keyPressed ("Numpad8") ', sendto.script)


Now that calls the function keyPressed with the argument "Numpad8" when that key is pressed. The function call to keyPressed has to be quoted as we want it deferred (to when the key is pressed) and not evaluated right now when AcceleratorTo is called.

The function keyPressed could look like this:


function keyPressed (which)
  local keyState = GetInfo (294)
  if which == 'Numpad8' and bit.band (0x080, keyState) ~= 0 then
    print ("Numpad8 and right-control pressed")
  elseif which == 'Numpad8' and bit.band (0x010, keyState) ~= 0 then
    print ("Numpad8 and left-control pressed")
  else
    print ("Some other key pressed")
  end -- if
  
end -- keyPressed


Notice that we are testing the key state inside the function.

However I wasn't getting that to work reliably, possibly because I test inside a virtual machine. You may be able to get some combination of those ideas to work.


Template:function=GetInfo GetInfo

The documentation for the GetInfo script function is available online. It is also in the MUSHclient help file.



Template:function=AcceleratorTo AcceleratorTo

The documentation for the AcceleratorTo script function is available online. It is also in the MUSHclient help file.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 28 Aug 2016 03:51 AM (UTC)

Amended on Sun 28 Aug 2016 03:58 AM (UTC) by Nick Gammon

Message
It looks like the documentation for the bit patterns in the help file is wrong (for GetInfo (294)). Below are the correct bits:


294 - Status of keyboard modifiers / mouse click, as follows:

      (values are in hexadecimal)

      0x00001 - shift key down (left or right)    
      0x00002 - control key down (left or right) 
      0x00004 - Alt key down (left or right)

      0x00008 - left shift key down     
      0x00010 - right shift key down     

      0x00020 - left control key down  
      0x00040 - right control key down

      0x00080 - left Alt key down  
      0x00100 - right Alt key down

      0x00200 - Caps Lock key down (right now)    
      0x00400 - Num Lock key down (right now)
      0x00800 - Scroll Lock key down (right now)

      0x02000 - Caps Lock key toggled (active)  
      0x04000 - Num Lock key  toggled (active)
      0x08000 - Scroll Lock key  toggled (active)

      0x10000 - Left mouse button down  
      0x20000 - Right mouse button down
      0x40000 - Middle mouse button down


I got it to work OK with the Alt key like this:


function keyPressed (which)
  local keyState = GetInfo (294)
  if which == 'Numpad8' and bit.band (0x080, keyState) ~= 0 then
    print ("Numpad8 and left-Alt pressed")
  elseif which == 'Numpad8' and bit.band (0x0100, keyState) ~= 0 then
    print ("Numpad8 and right-Alt pressed")
  else
    print ("Some other key pressed")
  end -- if
end -- keyPressed


With this to add the accelerator:


AcceleratorTo ("Alt+Numpad8" , ' keyPressed ("Numpad8") ', sendto.script)


I've uploaded the corrected documentation to this server, so it is OK now if you follow the link:

http://www.gammon.com.au/scripts/doc.php?function=GetInfo

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Sun 28 Aug 2016 06:00 AM (UTC)
Message
After re-reading your question I see you mentioned right-arrow, not right-ctrl, which is a bit different.

I don't think you can easily do that. The action of pressing right-arrow has an immediate effect - the cursor moves to the right in the command window.

I don't think you can reasonably defer that - just in case you press numpad-8 a moment later, that would annoy the hell out of a lot of users.

I think, though, that my suggestion of detecting right-control, right-alt or right-shift could still work for you. Those keys are fairly close to the numpad keys, so you could press them together without too much trouble.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


20,818 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.