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 

DLLCall: Support for Human Interface devices
Goto page Previous  1, 2, 3, 4, 5, 6
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Veil



Joined: 01 Apr 2008
Posts: 22
Location: Netherlands

PostPosted: Sun Apr 06, 2008 4:32 pm    Post subject: Reply with quote

kyvaith wrote:
Nope... it doesn't work

I have error popup saying that there is no mfc71.dll library..

What script are you running exactly when you get this popup?

I don't really know how this DLL file is connected to all this, but maybe this can help you:

http://pcsupport.about.com/od/findbyerrormessage/a/mfc71dll.htm
Back to top
View user's profile Send private message Send e-mail
kyvaith



Joined: 06 Apr 2008
Posts: 8

PostPosted: Sun Apr 06, 2008 4:38 pm    Post subject: Reply with quote

I double clicked on Apple Wireless Keyboard.ahk and I've get a box with title: FnMapper: AutoHotkey.exe File not found saying the same what title - there is no MFC71.dll library Confused

edit:

I think your new script accessing different things from windows api, that doesn't exist in RemoteControl.ahk... Mayby you could modified RemoteControl.ahk by removing all we doesn't need and adding procedure mapping fn key to control key and ejc key to delete key? It would be great.. Wink


edit2:

Ok it works Very Happy

Now, what could I do to remap fn to control and ejc to del? I need only this function - no winamp controls, no real ejc function. Could you help me?
Back to top
View user's profile Send private message
Veil



Joined: 01 Apr 2008
Posts: 22
Location: Netherlands

PostPosted: Sun Apr 06, 2008 5:09 pm    Post subject: Reply with quote

kyvaith wrote:
Ok it works Very Happy

Good news! This is with the Apple Wireless Keyboard.ahk right?

kyvaith wrote:
Now, what could I do to remap fn to control and ejc to del? I need only this function - no winamp controls, no real ejc function. Could you help me?

I stripped down the file to just the things you need. Copy the code below, and save it to a file. Make sure to place the file in the same directory as the DLL. Close all other scripts that are running, and then run this one.

Code:
;
; AutoHotkey Version: 1.x
; Language.........: English
; Platform.........: NT/XP/Vista
; Authors..........: Veil, Leon
; Full guide.......: http://brrp.mine.nu/fnkey/
;
; Script Function..: Remapping the Fn key
;
; Based on.........: DLLCall: Support for Human Interface devices
; By...............: Micha
; URL..............: http://www.autohotkey.com/forum/viewtopic.php?t=6367
;
; Use..............: Spread the word! Just be sure to credit the writer of the dll
;                               file and the   original config, and the authors of this file.
;

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;#NoTrayIcon


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; DLL registration and readout of keys
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Set screen title, to set the HWND
Gui, Show, x0 y0 h0 w0, FnMapper

; Variable for the modifier key, define it here, just to be sure
fnPressed := 0

; Set the homepath to the relevant dll file
HomePath=AutohotkeyRemoteControl.dll

; Load the dll
hModule := DllCall("LoadLibrary", "str", HomePath)

; On specific message from the dll, goto this function
OnMessage(0x00FF, "InputMsg")

; Register at the dll in order to receive events
EditUsage := 1
EditUsagePage := 12
HWND := WinExist("FnMapper")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
WinHide, FnMapper


; This function is called, when a WM_INPUT-msg from a device is received
InputMsg(wParam, lParam, msg, hwnd)
{
  DeviceNr = -1
  nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
  if (errorlevel <> 0) || (nRC == 0xFFFFFFFF)
  {
     MsgBox GetWM_INPUTHIDData fehlgeschlagen. Errorcode: %errorlevel%
     goto cleanup
  }
  ;Tooltip, %DeviceNr%
  ifequal, nRC, 2
  {
    ProcessHIDData(wParam, lParam)
  }
  else
  {
     MsgBox, Error - no HID data
  }
}
Return

ProcessHIDData(wParam, lParam)
{
   ; Make sure this variable retains its value outside this function
   global fnPressed
   
  DataSize = 5000
   VarSetCapacity(RawData, %DataSize%, 0)
   RawData = 1
  nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTHIDData", UINT, wParam, UINT, lParam, "UINT *" , DataSize, "UINT", &RawData, "Cdecl UInt")

  ; Get the ID of the device
  ; Use the line below to check where an event was sent from, when using this code for a new HID device
  ; DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl UInt")

  ;FirstValue := NumGet(RawData, 0,"UChar") ; something to do with the bits, not really relevant here
  KeyStatus := NumGet(RawData, 1, "UChar")
 
  ; MsgBox, Keystatus: %KeyStatus%
 
  ; Filter the correct bit, so that it corresponds to the key in question
  ; Add another Transform for a new key
 
  ; Filter bit 5 (Fn key)
  Transform, FnValue, BitAnd, 16, KeyStatus
 
  ; Filter bit 4 (Eject key)
  Transform, EjectValue, BitAnd, 8, KeyStatus
   
  if (FnValue = 16) {
      Send, {Ctrl down}
  } else {
      Send, {Ctrl up}
  }
 
  if (EjectValue = 8) {
      Send, {Delete}
  }
 
} ; END: ProcessHIDData

; If there was an error retrieving the HID data, cleanup
cleanup:
DllCall("FreeLibrary", "UInt", hModule)  ; It is best to unload the DLL after using it (or before the script exits).



ExitApp


So run this, and see if it works. The parts that are relevant for you are:

Code:
  if (FnValue = 16) {
      Send, {Ctrl down}
  } else {
      Send, {Ctrl up}
  }
 
  if (EjectValue = 8) {
      Send, {Delete}
  }


Last edited by Veil on Tue Jun 03, 2008 4:11 pm; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
kyvaith



Joined: 06 Apr 2008
Posts: 8

PostPosted: Sun Apr 06, 2008 5:20 pm    Post subject: Reply with quote

My genius Very Happy

almost... this new delete button is probably not keyboard class key, because it doesn't deleting by pressing and holding for a longer time.. i can delete letters by selective clicking key...

I've tried adding Return on the end of value but it's not this... It should read keyboard status in loop to read hold key i think

edit:

I tried to find answer in script that you submitted three posts ago for me and... It works there with fn+backspace - it's deleting by holding combination of keys, but you declared new function for key Backspace there (if fn is pressed use backspace like delete if not use normally like backspace). It could work here too, but You used a $Backspace value that doesn't exist for Eject key i think... Any ideas? Wink

edit2:

One more thing.. script don't recognizing new control button and new delete button pressed at one... so I can't make ctrl+alt+delete.... old ctrl+ regular alt + new delete work...

edit3:

I tried everything... but doesn't work repeating on del key.. I tried loop but this deleting for ever on one del click...
Back to top
View user's profile Send private message
kyvaith



Joined: 06 Apr 2008
Posts: 8

PostPosted: Tue Apr 08, 2008 2:20 pm    Post subject: Reply with quote

Anyone? Crying or Very sad Embarassed
Back to top
View user's profile Send private message
Veil



Joined: 01 Apr 2008
Posts: 22
Location: Netherlands

PostPosted: Wed Apr 09, 2008 3:21 am    Post subject: Reply with quote

Just build on what's already there.

kyvaith wrote:
I tried to find answer in script that you submitted three posts ago for me and... It works there with fn+backspace - it's deleting by holding combination of keys, but you declared new function for key Backspace there (if fn is pressed use backspace like delete if not use normally like backspace). It could work here too, but You used a $Backspace value that doesn't exist for Eject key i think... Any ideas? Wink

Yes, you probably need to use a loop, or a SetTimer. So:

Code:
if (EjectValue = 8) {
    PressedDelete := 1
} else {
    PressedDelete := 0
}

Now you know that this value is set correctly, depending on which key is pressed. Now *outside* this function, which retrieves the HID data, do something with this value. Loop delete, until PressedDelete = 0, or something in that direction.

kyvaith wrote:
One more thing.. script don't recognizing new control button and new delete button pressed at one... so I can't make ctrl+alt+delete.... old ctrl+ regular alt + new delete work...

You already know when and if the Fn *and* Eject keys are pressed. So you can add to the script:

Code:
if (EjectValue = 8 && FnValue=16) {
   CtrlDelPressed := 1
} else {
   CtrlDelPressed := 0
}

Then, when pressing Alt, do something depending on the value CtrlDelPressed. Check the documentation for "GetKeyState". This is the same thing, except since they're not keys that AHK detects by default, you set their state using this trick.
Back to top
View user's profile Send private message Send e-mail
kyvaith



Joined: 06 Apr 2008
Posts: 8

PostPosted: Tue Apr 15, 2008 6:34 pm    Post subject: Reply with quote

Hi again...

Well,I have bad news Crying or Very sad

I couldn't get this to work... I thinking about this by few days, but I'm not programist, and I couldn't find method...
I now, that this is to much, because You are here only to show the way how it's works, but maybe You could make it for me? ;/ It would be great.
If this forum supports any help points I'll give You some. Very Happy
Back to top
View user's profile Send private message
kyvaith



Joined: 06 Apr 2008
Posts: 8

PostPosted: Sat Apr 19, 2008 2:32 pm    Post subject: Reply with quote

I still believe, that someone could help me. Crying or Very sad Please - it's important for me.
Back to top
View user's profile Send private message
ejp
Guest





PostPosted: Sat May 10, 2008 8:14 am    Post subject: Reply with quote

I've recently started using AHK, and I'm picking things up fairly easy, but I think I'm having some trouble. Firstly, thanks for the script -- I'm trying to remap the MCE button on my MCE remote.

To make things simple, let's say I want to open up Notepad with it; I can do that fine. However, once Notepad is open and active, I want the MCE button to no longer do anything -- I don't want to "accidentally" run another instance of Notepad.

Does anyone know how to do this?
Back to top
Palomar



Joined: 28 May 2008
Posts: 3
Location: NL

PostPosted: Thu May 29, 2008 11:46 am    Post subject: Reply with quote

Veil wrote:
kyvaith wrote:
Ok it works Very Happy

Good news! This is with the Apple Wireless Keyboard.ahk right?

kyvaith wrote:
Now, what could I do to remap fn to control and ejc to del? I need only this function - no winamp controls, no real ejc function. Could you help me?

I stripped down the file to just the things you need. Copy the code below, and save it to a file. Make sure to place the file in the same directory as the DLL. Close all other scripts that are running, and then run this one.

Code:
;
; AutoHotkey Version: 1.x
; Language.........: English
; Platform.........: NT/XP/Vista
; Author...........: Thomas Veil, Leon Schoorl
; Full guide.......: http://brrp.mine.nu/fnkey/
;
; Script Function..: Remapping the Fn key
;
; Based on.........: DLLCall: Support for Human Interface devices
; By...............: Micha
; URL..............: http://www.autohotkey.com/forum/viewtopic.php?t=6367
;
; Use..............: Spread the word! Just be sure to credit the writer of the dll
;                               file and the   original config, and the authors of this file.
;

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;#NoTrayIcon


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; DLL registration and readout of keys
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Set screen title, to set the HWND
Gui, Show, x0 y0 h0 w0, FnMapper

; Variable for the modifier key, define it here, just to be sure
fnPressed := 0

; Set the homepath to the relevant dll file
HomePath=AutohotkeyRemoteControl.dll

; Load the dll
hModule := DllCall("LoadLibrary", "str", HomePath)

; On specific message from the dll, goto this function
OnMessage(0x00FF, "InputMsg")

; Register at the dll in order to receive events
EditUsage := 1
EditUsagePage := 12
HWND := WinExist("FnMapper")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
WinHide, FnMapper


; This function is called, when a WM_INPUT-msg from a device is received
InputMsg(wParam, lParam, msg, hwnd)
{
  DeviceNr = -1
  nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
  if (errorlevel <> 0) || (nRC == 0xFFFFFFFF)
  {
     MsgBox GetWM_INPUTHIDData fehlgeschlagen. Errorcode: %errorlevel%
     goto cleanup
  }
  ;Tooltip, %DeviceNr%
  ifequal, nRC, 2
  {
    ProcessHIDData(wParam, lParam)
  }
  else
  {
     MsgBox, Error - no HID data
  }
}
Return

ProcessHIDData(wParam, lParam)
{
   ; Make sure this variable retains its value outside this function
   global fnPressed
   
  DataSize = 5000
   VarSetCapacity(RawData, %DataSize%, 0)
   RawData = 1
  nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTHIDData", UINT, wParam, UINT, lParam, "UINT *" , DataSize, "UINT", &RawData, "Cdecl UInt")

  ; Get the ID of the device
  ; Use the line below to check where an event was sent from, when using this code for a new HID device
  ; DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl UInt")

  ;FirstValue := NumGet(RawData, 0,"UChar") ; something to do with the bits, not really relevant here
  KeyStatus := NumGet(RawData, 1, "UChar")
 
  ; MsgBox, Keystatus: %KeyStatus%
 
  ; Filter the correct bit, so that it corresponds to the key in question
  ; Add another Transform for a new key
 
  ; Filter bit 5 (Fn key)
  Transform, FnValue, BitAnd, 16, KeyStatus
 
  ; Filter bit 4 (Eject key)
  Transform, EjectValue, BitAnd, 8, KeyStatus
   
  if (FnValue = 16) {
      Send, {Ctrl down}
  } else {
      Send, {Ctrl up}
  }
 
  if (EjectValue = 8) {
      Send, {Delete}
  }
 
} ; END: ProcessHIDData

; If there was an error retrieving the HID data, cleanup
cleanup:
DllCall("FreeLibrary", "UInt", hModule)  ; It is best to unload the DLL after using it (or before the script exits).



ExitApp


So run this, and see if it works. The parts that are relevant for you are:

Code:
  if (FnValue = 16) {
      Send, {Ctrl down}
  } else {
      Send, {Ctrl up}
  }
 
  if (EjectValue = 8) {
      Send, {Delete}
  }

Hi,
Thanks for this script. It works, but it doesn't allow you to keep the key pressed (held down). I.e. in a second script I've remapped ctrl+right to page_down, but when pressing Fn+right, page down is pressed once. I cannot scroll to the very bottom of the page by one keypress. Instead, I do have to release Fn + right_arrow keys and press them again to do a 'page down' again.

So what I'd like to see is when pressing Fn, it will be held down until I release it. Should that be possible??
Back to top
View user's profile Send private message
Ron1



Joined: 20 Dec 2007
Posts: 34
Location: United States of America

PostPosted: Sun Jun 01, 2008 9:18 pm    Post subject: DLLCall: Support for Human Interface devices Reply with quote

Micha,

Thank you for your excellent work on the "DLLCall: Support for Human Interface devices". I am studying it now in an effort to understand it, so that I can begin using it.

While doing so, I wanted to be sure I had your latest code, and went to your page:

http://www.autohotkey.net/~Micha/HIDsupport/Autohotkey.html

There I found the date code at the bottom -- 27:08:08 -- which appears to need a correction. I assume you mean August 8, 2007, rather than 2008, and that this is, indeed, the latest version.

I hope that Chris can add to AutoHotkey support for multiple input devices, such as multiple mice, multiple keyboards, and multiple keypads in the near future. Of course, there is always more to do than anyone can do, and we are all so grateful for what AutoHotkey is already offering.

My goal is to use two mice simultaneously. The first mouse would work as a regular mouse. The second mouse would serve as an inexpensive source of some additional programmable buttons for an Assistive Technology application. But I must somehow block the pass-through of the second mouse's normal signals to WinXP so that only the substituted hotkeys are executed. I see that there is some discussion of this type of issue on the Forum, and I am hoping to find a solution.

Again, my appreciation for your good work.

Regards,

Ron1
Back to top
View user's profile Send private message
Micha



Joined: 15 Nov 2005
Posts: 433
Location: Germany

PostPosted: Mon Jun 02, 2008 7:05 pm    Post subject: Reply with quote

Hi, Ron1
thanks for your kind words.
I've corrected the date. I really meant 2007 Smile

For your problem with 2 mice I have no idea how to achive this. If you plug in 2 mice, you can use both with windows.
You want to deavticate the movements of the second mouse but the buttons should be used by your script.
I'm not sure if this is possible at all

Ciao
Micha
Back to top
View user's profile Send private message
Lizzy
Guest





PostPosted: Tue Jul 08, 2008 3:29 pm    Post subject: Reply with quote

I've looked over the instructions and guides for mapping special keys using this driver. And there are two questions/issues I have with the procedure:


1. When using the Register Tool, how do you choose the right device, Useage and Useage Page? Do you just randomly start choosing devices and randomly type different numbers into the Useage and Useage Page fields until it works?

2. What happens with all the attempts you make registering trial and errors? Are you making changes to your system that aren't going to be undone? Or are they undone once you exit the script? Or can you do something afterwards to delete all the ones you tried except for the final combination that worked?
Back to top
Micha



Joined: 15 Nov 2005
Posts: 433
Location: Germany

PostPosted: Tue Jul 08, 2008 5:02 pm    Post subject: Reply with quote

Hi Lizzy,
Quote:
1. When using the Register Tool, how do you choose the right device, Useage and Useage Page?

Mouse (2,1) and keyboard (6,1) have fix values. For HID-Devices I'm calling the API of GetRawInputDeviceInfo which filles an struct with a lot of infos of the device. The values for Usage and UsagePage are retrieved by this call.


Quote:
2. What happens with all the attempts you make registering trial and errors? Are you making changes to your system that aren't going to be undone? Or are they undone once you exit the script? Or can you do something afterwards to delete all the ones you tried except for the final combination that worked?

If you are registering all devices, you'll receive all input messages.
I've found the API call RegisterRawInputDevices but I haven't found an UN-RegisterRawInputDevices. A member wrote that you can use RegisterRawInputDevices with the parameter RIDEV_REMOVE to cancel receiving the messages but I haven't implemented or tested that yet.
You have to provide a window which receives the messages (I've used the ahk-window) If you exit the script the window is destroyed and no more messages are received but it's possible that the system still tries to send the message but cannot find the window any more.

My dll is just a wrapper for API-calls with structs with was complicated and errorprone with ahk. Now you could use helperscripts from other members to create the struct and calling the api directly.
I still like to use dlls to hide complicated things.
I'm very busy at the moment so I think I cannot implement or test the RIDEV_REMOVE flag this year. If you want to you can call the api directly. Have a look at the MSDN documentation for RegisterRawInputDevices.
Ciao
Micha
Back to top
View user's profile Send private message
Lizzy
Guest





PostPosted: Tue Jul 08, 2008 9:00 pm    Post subject: Reply with quote

Micha wrote:


Quote:


2. What happens with all the attempts you make registering trial and errors? Are you making changes to your system that aren't going to be undone? Or are they undone once you exit the script? Or can you do something afterwards to delete all the ones you tried except for the final combination that worked?




If you are registering all devices, you'll receive all input messages.
I've found the API call RegisterRawInputDevices but I haven't found an UN-RegisterRawInputDevices. A member wrote that you can use RegisterRawInputDevices with the parameter RIDEV_REMOVE to cancel receiving the messages but I haven't implemented or tested that yet.
You have to provide a window which receives the messages (I've used the ahk-window) If you exit the script the window is destroyed and no more messages are received but it's possible that the system still tries to send the message but cannot find the window any more.




I'm still unclear what the scope of the changes will be. If I run the register tool, register a bunch of stuff through trial and error to find what I need, and reboot - will the OS be in the exact same state and configuration it was before I ever ran the tool? Or will it have been changed?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6
Page 6 of 6

 
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