Page 7 of 18
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 29 Jun 2018, 13:06
by evilC
Tweaked some stuff to try and debug what is going on with PS/2 devices.
I altered the GetDeviceList() function to return all devices, even those without a VID and PID
This should make *something* appear in the monitor script for PS/2 devices
Furthermore I added a "Handle" parameter, so we can see the raw device handles
Attached a zip with the changed files
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 30 Jun 2018, 12:02
by malcev
Thank You. It works now.
How can I remap up key?
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 30 Jun 2018, 16:15
by evilC
@malcev I see no issue with subscribing to up and down, but I do see an issue with SendKeyEvent and ScanCodes > 256
Test script (Should remap Up to Down and vice versa):
Code: Select all
#SingleInstance force
#Persistent
#include Lib\AutoHotInterception.ahk
AHI := new AutoHotInterception()
;~ keyboardId := AHI.GetKeyboardId(0x04F2, 0x0112)
keyboardId := AHI.GetKeyboardId(0x413C, 0x2107)
AHI.SubscribeKey(keyboardId, GetKeySC("Up"), true, Func("KeyEvent").Bind(GetKeySC("Down")))
AHI.SubscribeKey(keyboardId, GetKeySC("Down"), true, Func("KeyEvent").Bind(GetKeySC("Up")))
return
KeyEvent(code, state){
global AHI, keyboardId
AHI.SendKeyEvent(keyboardId, code, state)
ToolTip % "State: " state
}
^Esc::
ExitApp
The way Interception represents right variants of keys (eg Right ALT etc) means that if SC is > 256, I do some custom logic.
This seems to not work for arrow keys
Attached is a replacement DLL which should let you send arrow keys, but I am not sure how to deal with this going forwards.
I have raised an
Issue on GitHub regarding this
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 30 Jun 2018, 16:18
by evilC
Oh, and if it now works with the PS/2 keyboard, could you possibly paste a screenshot of the monitor?
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 08:13
by malcev
How can I use keyboardId := AHI.GetKeyboardId(0x413C, 0x2107) with handle only?
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 12:22
by evilC
malcev wrote:
How can I use keyboardId := AHI.GetKeyboardId(0x413C, 0x2107) with handle only?
You can't at the moment, which is what I intend to rectify.
For the time being, you can just pass the interception ID instead.
eg
Code: Select all
keyboardId := 1
AHI.SubscribeKey(keyboardId, GetKeySC("Up"), true, Func("KeyEvent").Bind(GetKeySC("Down")))
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 12:37
by evilC
Attached is a test of a new version that should let you get device ID from handle
Added methods:
GetKeyboardIdFromHandle(handle, instance := 1)
GetMouseIDFromHandle(handle, instance := 1)
Please test it all works for you, and I will push out a new release
I am guessing AHI.GetKeyboardIdFromHandle("ACPI\PNP0303") should work for you
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 12:52
by malcev
I think here is error:
Code: Select all
GetKeyboardIdFromHandle(handle, instance := 1){
return this.GetDeviceId(false, handle, instance)
}
GetMouseIDFromHandle(handle, instance := 1){
return this.GetDeviceId(true, handle, instance)
}
It should be:
Code: Select all
GetKeyboardIdFromHandle(handle, instance := 1){
return this.GetDeviceIdFromHandle(false, handle, instance)
}
GetMouseIDFromHandle(handle, instance := 1){
return this.GetDeviceIdFromHandle(true, handle, instance)
}
And if I use this code
Code: Select all
#SingleInstance force
#Persistent
#include Lib\AutoHotInterception.ahk
AHI := new AutoHotInterception()
keyboardId := 1
AHI.SubscribeKey(keyboardId, GetKeySC("Up"), true, Func("KeyEvent").Bind(GetKeySC("Down")))
AHI.SubscribeKey(keyboardId, GetKeySC("Down"), true, Func("KeyEvent").Bind(GetKeySC("Up")))
return
KeyEvent(code, state){
global AHI, keyboardId
AHI.SendKeyEvent(keyboardId, code, state)
ToolTip % "State: " state
}
then "up" remaps to "P" and down remaps to "H".
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 13:02
by evilC
Good catch on the first one
Regarding the up/down not mapping again - that did not make it into this commit. The version I posted for you before was a bodge just to make sure I identified what the issue was.
I will be looking into a proper fix for that one ASAP
Attached is a DLL with these new changes, and the Up/Down bodge
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 13:05
by malcev
Now it works.
Thank You!
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 13:31
by evilC
AHA! I took another look at the code that deals with ScanCode > 255, and it was broken for all of them, not just up.
Old code:
Code: Select all
public void SendKeyEvent(int id, ushort code, int state)
{
var stroke = new ManagedWrapper.Stroke();
if (code > 255)
{
code -= 256;
state += 2;
}
stroke.key.code = code;
stroke.key.state = (ushort)(1 - state);
ManagedWrapper.Send(_deviceContext, id, ref stroke, 1);
}
DUH!! Interception uses 0 for press, 1 for release, or +2 to each of those if extended.
The above logic clearly only works properly when ScanCodes are < 256
It should do 1-state, and THEN add 2 if needed
New code:
Code: Select all
public void SendKeyEvent(int id, ushort code, int state)
{
IsValidDeviceId(false, id);
var st = 1 - state;
var stroke = new ManagedWrapper.Stroke();
if (code > 255)
{
code -= 256;
st += 2;
}
stroke.key.code = code;
stroke.key.state = (ushort)st;
ManagedWrapper.Send(_deviceContext, id, ref stroke, 1);
}
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 02 Jul 2018, 14:06
by evilC
AHI 0.3.5 has been released!
Adds support for Horizontal Wheel on Mice - thanks @crumbl3d !
Instance is now correctly passed through in GetDeviceID and variants
GetDeviceIdFromHandle, GetKeyboardIdFromHandle, GetMouseIDFromHandleadded to enable support for PS/2 and Laptop devices
Fix for SendKeyEvent when using ScanCodes > 255
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 06 Jul 2018, 17:48
by serzh82saratov
Code: Select all
MonitorWrapper := new AutoHotInterception("Monitor")
Monitor := MonitorWrapper.Instance
Monitor.Subscribe(Func("KeyboardEvent"), Func("MouseEvent"))
And then how to unload an object MonitorWrapper, and unsubscribe?
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 07 Jul 2018, 04:50
by serzh82saratov
evilC wrote:Adds support for Horizontal Wheel on Mice
Code: Select all
AHI.Instance.SendMouseButtonEvent(12, 6, 1)
I tried it but nothing happens, should the mouse physically support it?
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 07 Jul 2018, 06:59
by serzh82saratov
I now understand it is necessary to use to unsubscribe
Code: Select all
Monitor.SetDeviceFilterState(dev.id, 0)
But is it necessary to destroy the Monitor and MonitorWrapper objects?
And where to read about SetDeviceFilterState and the rest?
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 07 Jul 2018, 10:48
by serzh82saratov
Fix for SendKeyEvent when using ScanCodes > 255
It is impossible to send Numlock - sc145.
Although it sends sc145 but at the same time vkFF is not vk90.
But if to send sc45 then it is defined as Numlock, although sc45 is Pause.
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 09 Jul 2018, 07:22
by evilC
The Monitor was never designed to be loaded / unloaded dynamically
I will look into the NumLock issue and the sending wheel when I get a chance - in the meantime, I have raised issues
#18 and
#19
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 09 Jul 2018, 07:46
by serzh82saratov
evilC wrote:The Monitor was never designed to be loaded / unloaded dynamically
SubscribeKey too it is impossible to unloaded ?
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 09 Jul 2018, 08:03
by evilC
Currently, yes, but I don't think it would be too hard to implement.
Added enhancement request
#20
Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!
Posted: 09 Jul 2018, 08:07
by serzh82saratov
It seems to me that in such a topic it is necessary to unload all methods, including the instance itself.