AutoHotkey Community

It is currently May 26th, 2012, 12:57 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 152 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9, 10, 11  Next
Author Message
 Post subject:
PostPosted: December 13th, 2008, 8:25 pm 
Offline

Joined: December 20th, 2007, 4:12 am
Posts: 22
whoops... I told you I was new at this, although I thought I knew how to use a forum... :oops:

Ok let me try this again... Lets imagine that I had a simple script that would simply beep a high tone when I pressed the space key and beep a low tone when I pressed the left mouse button.

Code:
space:: SoundBeep, 3000, 100  ; Play a high pitch for half a second.
LButton:: SoundBeep, 200, 100  ; Play a low pitch for half a second.


Now lets say I wanted to use Micha's DLL to allow me to devote a second keyboard and second mouse to these and other hotkeys. Here is how I would like things to work.

________________________

- When the "hotkey keyboard's" space key is pressed or the "hotkey mouse's" left button is clicked, sounds should be played.

- The "hotkey keyboard" and "hotkey mouse" should no longer send these keystrokes or mouse clicks to to the current application.

- The "regular keyboard's" keys and "regular mouse's" buttons should function unaffected. So when the space key on the regular keyboard is pressed, the current application simply receives the space character.

________________________

Could someone please create a labeled script that would do this? Eventually I would like to map a function for each of the hotkey keyboard's keys and each of the hotkey mouse's buttons and movements. But I really do need a model script that will get me started. Thanks...

_________________________________________________________

Here's the data I get from the AutoHotkeyRemoteControlDLL script:
_________________________________________________________

My regular keyboard is registering as a keyboard with Device ID 7.
My hotkey keyboard is registering as a keyboard with Device ID 3.
Usage for both is 6 and UsagePage for both is 1.

When the space key is pressed on either keyboard I receive:

Code:
MakeCode: 57
Flags: 1
Key: 32
Msg: 257
Extrainfo: 0

_________________________________________________________

My regular mouse is registering as a mouse with Device ID 11.
My hotkey mouse is registering as a mouse with Device ID 10.
Usage for both is 2 and UsagePage for both is 1.

When the left mouse button is pressed on either mouse I receive:

Code:
Flags: 0
BtnFlag: 1
ButtonData: 0
RawButton: 0
X: 0
Y: 0
Extrainfo: 0


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2008, 1:10 pm 
Offline

Joined: November 26th, 2008, 4:13 pm
Posts: 12
I Love You, Man!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2008, 2:22 am 
Offline

Joined: September 26th, 2007, 11:18 pm
Posts: 101
thanks for the answer.

This method of using a combination which is normally not used - that's a good idea, but I would like to retain the Logitech functionality in all the other applications.

That is:

resize window and drag lock


Sure enough, there must be a way to replicate these functions with AHK, but b4 I start, just one question again:

can't Logitech mouse's buttons be monitored to see their ID and taken over as any other buttons or keys?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2008, 3:28 pm 
Offline

Joined: January 14th, 2008, 9:10 pm
Posts: 35
Location: Germany
@rockum & TOTAL:
I'm currently working on a version of Micha's script that can determine if a certain key was sent from one keyboard or another (or in my case from a remote or from a keyboard). I'll post it soon.

@TOTAL:
So far Micha's script doesn't seem to disable any functionality of other programs, so your Logitech software should work normally.
The mouse buttons should be programmable like all the other stuff, but still you would have the normal functionality of those buttons in addition to AHK-functionality.

@everybody:
I don't see a way to disable the "old functionality" of a certain key or button. Meaning I can program additional features to a button, but it still sends the default function to windows.
Any help on this would be welcome.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2008, 4:27 pm 
Thanks elmulti, good luck.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2008, 6:39 pm 
Offline

Joined: January 14th, 2008, 9:10 pm
Posts: 35
Location: Germany
OK, here is the changed "RemoteControl.ahk".
You have to adjust the values for your devices. Then it should give you information about the pressed and released keys in a tool tip.
I included an example for the "left" key being pressed on different devices. Adjust the device numbers to what you find in the tool tip and replace the message box with your custom code.
The script can be closed by pressing Win+C.

Note that this still doesn't deactivate any key in any way, it just adds functionality.

Hope this helps somebody out.
good luck, elmulti
Code:
; based on code by Micha
; changed by elmulti
; please adjust EditUsage and EditUsagePage for your devices

#SingleInstance force
; path to AutohotkeyRemoteControl.dll
HomePath=AutohotkeyRemoteControl.dll
; load the dll
hModule := DllCall("LoadLibrary", "str", HomePath)  ; Avoids the need for DllCall() in
OnMessage(0x00FF, "InputMsg")
DetectHiddenWindows, on
SetTimer,UPDATEDSCRIPT,1000 ; for testing and developing
info_text := ""            ; for testing only

; register first device
EditUsage = 6
EditUsagePage = 1
Gui, Show, Hide x0 y0 h0 w0, Autohotkey HID-Support
HWND := WinExist("Autohotkey HID-Support")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
   MsgBox RegisterDevice failed. Errorcode: %errorlevel%
   goto cleanup
}

; register second device (you can remove this part to use only one device)
EditUsage = 1      ; for mouse use: EditUsage = 2
EditUsagePage = 12   ; for mouse use: EditUsagePage = 1
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
   MsgBox RegisterDevice failed. Errorcode: %errorlevel%
   goto cleanup
}

Return


InputMsg(wParam, lParam, msg, hwnd)
{
   ; for testing only
   Global info_text
   info_text := "------------------------`n" . info_text
   
   DeviceNr = -1
   ; get device number and type
   nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
   if (errorlevel <> 0) || (nRC == 0xFFFFFFFF)
   {
      MsgBox GetWM_INPUTHIDData failed. Errorcode: %errorlevel%
      goto cleanup
   }
 
   ifequal, nRC, 0   ; device is a mouse
   {
      ; process mouse data
      nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTMOUSEData", UINT, wParam, UINT, lParam, "UINT *" , pusFlags, "UINT *", pusBtnFlg
      , "UINT *" , pusBtnData, "UINT *", pulRawBtn, "UINT *" , px, "UINT *", py, "UINT *", pextraInfo, "Cdecl UInt")   
      if (errorlevel <> 0) || (nHandle == -1)
      {
         MsgBox GetWM_INPUTMOUSEData failed. Errorcode: %errorlevel%
         goto cleanup
      }
      
      DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl Int")
      DeviceNumber := DeviceNumber +1 ;Index 0
      
      ; for testing only
      ; display a tooltip with the mouse info
      info_text := "Mouse-Input `nDevicenumber: " . DeviceNumber . " `nFlags: " . pusFlags . " `nBtnFlag: " . pusBtnFlg . " `nButtonData: " . pusBtnData . " `nRawButton: " . pulRawBtn . " `nX: " . px . " `nY: " . py . " `nExtrainfo: " . pextraInfo . "`n" . info_text
      Tooltip %info_text%
      SetTimer, RemoveToolTip, 3000
      
   }
   else ifequal, nRC, 1   ; device is a keyboard
   {
      ; Keyboard data
      nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTKEYBOARDData", UINT, wParam, UINT, lParam, "UINT *" , pusMakeCode, "UINT *", pusFlags
        , "UINT *" , pusKey, "UINT *", punMsg, "UINT *", pextraInfo, "Cdecl UInt")   
      if (errorlevel <> 0) || (nHandle == -1)
      {
         MsgBox GetWM_INPUTKEYBOARDData failed. Errorcode: %errorlevel%
         goto cleanup
      }
      
      DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl Int")
      DeviceNumber := DeviceNumber +1 ;Index 0
      
      ; for testing only
      ; display a tooltip with the key info
      info_text := "Keyboard-Input `nDevice: " . DeviceNumber . "`nKey: " . pusKey . "`nMsg: " . punMsg . "`n" . info_text
      Tooltip %info_text%
      SetTimer, RemoveToolTip, 3000
      ; %punMsg% = 256 -> Button down, %punMsg% = 257 -> Button up
      

      if DeviceNumber = 6
      {
         if pusKey = 37
         {
            MsgBox You pressed "Left" on device 6!
         }
      }
      else if DeviceNumber = 5
      {
         if pusKey = 37
         {
            MsgBox You pressed "Left" on device 5!
         }
      }
   }

   else ifequal, nRC, 2 ; device is not a keyboard or mouse
   {
      DataSize = 5000
      VarSetCapacity(RawData, %DataSize%)
      ;Write something into the var, so the script won't be aborted :
      RawData = 1
      nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTHIDData", UINT, wParam, UINT, lParam, "UINT *" , DataSize, "UINT", &RawData, "Cdecl UInt")   
      if (errorlevel <> 0) || (nHandle == -1)
      {
         MsgBox GetWM_INPUTHIDData failed. Errorcode: %errorlevel%
         goto cleanup
      }
      
      DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl UInt")
      
      loop, %DataSize%
      {
         Zahl := NumGet(RawData, a_index-1,"UChar")
         Zahl := Dez2Hex(Zahl)   
         Vals = %Vals%%Zahl%     
      }
      
      ; for testing only
      ; display a tooltip with the button info
      info_text := "HID-Button: " . vals . "`nDevice: " . DeviceNumber . "`n" . info_text
      Tooltip %info_text%
      SetTimer, RemoveToolTip, 3000
      
      ; perform action for the corresponding button
      ifequal, Vals, 048000, gosub RED 
      ifequal, Vals, 040800, gosub GREEN
      ifequal, Vals, 041000, gosub YELLOW
      ifequal, Vals, 042000, gosub BLUE
   }

   ; for testing only
   info_text_length := StrLen(info_text)
   If info_text_length > 500
      info_text_length = 500
   info_text := SubStr(info_text, 1 , info_text_length)

}


; for remote control buttons
RED:
   Msgbox Red Button
Return

GREEN:
   Msgbox Green Button
Return

YELLOW:
   Msgbox Yellow Button
Return

BLUE:
   Msgbox Blue Button
Return



Dez2Hex(Number)
{
    format = %A_FormatInteger%    ; save original integer format
    SetFormat Integer, Hex        ; for converting bytes to hex
    Number += 0
    SetFormat Integer, %format%   ; restore original format
    StringTrimLeft, Number, Number, 2
    Stringlen := StrLen(Number)
    if Stringlen < 2
    Number = 0%Number%
    return Number
}   

; automatically updates the script as soon as it is changed
UPDATEDSCRIPT:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%

      SplashTextOn,,,Updated Script,
      Sleep,500
      Reload
   }
Return

; for testing only
RemoveToolTip:
   SetTimer, RemoveToolTip, Off
   info_text := ""
   ToolTip
Return

; Win+C will exit the script
#c::
   Gosub cleanup
Return   

cleanup:
   DllCall("FreeLibrary", "UInt", hModule)  ; It is best to unload the DLL after using it (or before the script exits).
ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2008, 3:06 am 
Offline

Joined: December 20th, 2007, 4:12 am
Posts: 22
Thanks Elmulti! I thought about trying to grab every key event and then just passing on the ones from the "wrong" device.

Something like this, but incorporated into your script.

Code:
#usehook
Lcontrol:: Send {Lcontrol}
Lwin:: Send {LWin}
Lalt:: Send {Lalt}
space:: Send {space}
Ralt:: Send {RAlt}
Rwin:: Send {Rwin}
AppsKey:: Send {AppsKey}
Rcontrol:: Send {Rcontrol}
Shift:: Send {Shift}
z:: Send z
x:: Send x
c:: Send c
v:: Send v
b:: Send b
n:: Send n
m:: Send m
,:: Send `,
.:: Send .
/:: Send /
Capslock:: Send {CapsLock}
a:: Send a
s:: Send s
d:: Send d
f:: Send f
g:: Send g
h:: Send h
j:: Send j
k:: Send k
l:: Send l
`;:: Send `;
':: Send '
Return:: Send {enter}
Tab:: Send {tab}
q:: Send q
w:: Send w
e:: Send e
r:: Send r
t:: Send t
y:: Send y
u:: Send u
i:: Send i
o:: Send o
p:: Send p
[:: Send [
]:: Send ]
\:: Send \
`:: Send ``
1:: Send 1
2:: Send 2
3:: Send 3
4:: Send 4
5:: Send 5
6:: Send 6
7:: Send 7
8:: Send 8
9:: Send 9
0:: Send 0
-:: Send -
=:: Send =
backspace:: Send {backspace}
Esc:: Send {Esc}
F1:: Send {F1}
F2:: Send {F2}
F3:: Send {F3}
F4:: Send {F4}
F5:: Send {F5}
F6:: Send {F6}
F7:: Send {F7}
F8:: Send {F8}
F9:: Send {F9}
F10:: Send {F10}
F11:: Send {F11}
F12:: Send {F12}
Left:: Send {Left}
Down:: Send {Down}
Right:: Send {Right}
Up:: Send {Up}
Delete:: Send {Delete}
End:: Send {End}
PgDn:: Send {PgDn}
Insert:: Send {Insert}
Home:: Send {Home}
PgUp:: Send {PgUp}
Printscreen:: Send {Printscreen}
Scrolllock:: Send {Scrolllock}
Pause:: Send {Pause}
Numpad0:: Send {Numpad0}
NumpadDot:: Send {NumpadDot}
NumPadEnter:: Send {NumPadEnter}
Numpad1:: Send {Numpad1}
Numpad2:: Send {Numpad2}
Numpad3:: Send {Numpad3}
Numpad4:: Send {Numpad4}
Numpad5:: Send {Numpad5}
Numpad6:: Send {Numpad6}
Numpad7:: Send {Numpad7}
Numpad8:: Send {Numpad8}
Numpad9:: Send {Numpad9}
NumpadAdd:: Send {NumpadAdd}
NumLock:: Send {NumLock}
Numpaddiv:: Send {Numpaddiv}
NumpadMult:: Send {NumpadMult}
NumpadSub:: Send {NumpadSub}


This didn't work however. The shift doesn't produce capital letters. I guess a command could be created for every possible combination. Surely there must be a more elegant way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2008, 5:31 pm 
Offline

Joined: January 14th, 2008, 9:10 pm
Posts: 35
Location: Germany
It's not elegant, but if you could make it work, it still would be a solution. *g*

When I try "Left:: Send {Left}" or "$Left:: Send {Left}" in my script, the script doesn't trigger any of the message boxes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2008, 5:56 pm 
Offline

Joined: December 20th, 2007, 4:12 am
Posts: 22
Hmm, I guess it is catching the hotkeys before they have a chance to act as triggers for the dll. I wonder if there is a way to "turn off" a device's function, but still keep receiving it's data. It might have to stop registering as a keyboard but still register as a HID for example. ????


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 29th, 2008, 6:17 pm 
Hallo Everybody,

I've got the same problem like Cholito (posted on page 7).
We both got the A4Tech WOP-35 Mouse with 2 different mousewheels.

I've got the same values as he got, but unfortunateley his script doesen't work, AHK can't discriminate both wheels independently.


In my case, i only want to the 2 wheels to give me 4 Different letters.
like...
FOREMOST WHEEL upward send, {w}
FoREMOST WHEEL downward send, {s}
REARWHEEL upward send, {e}
REARWHEEL downward send, {d}
and one letter for the 3rd mousebutton.

Can somebody please, please help us? (look at his post down on page 7)

Best regards
Ucla


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2008, 12:30 am 
Offline

Joined: January 14th, 2008, 9:10 pm
Posts: 35
Location: Germany
Hi Ucla,
please try the script below and let me know if there are any values, that differ between the two mouse wheels.
If the same action on different wheels results in exactly the same values (including the device number) then I don't see a way to tell one wheel from the other using Micha's script.
Good luck
Code:
; based on code by Micha
; changed by elmulti
; this one is for mouse input only

#SingleInstance force
; path to AutohotkeyRemoteControl.dll
HomePath=AutohotkeyRemoteControl.dll
; load the dll
hModule := DllCall("LoadLibrary", "str", HomePath)  ; Avoids the need for DllCall() in
OnMessage(0x00FF, "InputMsg")
DetectHiddenWindows, on
OnExit, cleanup
SetTimer,UPDATEDSCRIPT,1000 ; for testing and developing
info_text := ""            ; for testing only

; register mouse
EditUsage = 2
EditUsagePage = 1
Gui, Show, Hide x0 y0 h0 w0, Autohotkey HID-Support
HWND := WinExist("Autohotkey HID-Support")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
   MsgBox RegisterDevice failed. Errorcode: %errorlevel%
   goto cleanup
}

Return


InputMsg(wParam, lParam, msg, hwnd)
{
   ; for testing only
   Global info_text
   info_text := "------------------------`n" . info_text
   
   DeviceNr = -1
   ; get device number and type
   nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
   if (errorlevel <> 0) || (nRC == 0xFFFFFFFF)
   {
      MsgBox GetWM_INPUTHIDData failed. Errorcode: %errorlevel%
      goto cleanup
   }
 
   ifequal, nRC, 0   ; device is a mouse
   {
      ; process mouse data
      nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTMOUSEData", UINT, wParam, UINT, lParam, "UINT *" , pusFlags, "UINT *", pusBtnFlg
      , "UINT *" , pusBtnData, "UINT *", pulRawBtn, "UINT *" , px, "UINT *", py, "UINT *", pextraInfo, "Cdecl UInt")   
      if (errorlevel <> 0) || (nHandle == -1)
      {
         MsgBox GetWM_INPUTMOUSEData failed. Errorcode: %errorlevel%
         goto cleanup
      }
      
      DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl Int")
      DeviceNumber := DeviceNumber +1 ;Index 0
      
      
      ; for testing only
      ; display a tooltip with the mouse info
      info_text := "Mouse-Input `nDevicenumber: " . DeviceNumber . " `nFlags: " . pusFlags . " `nBtnFlag: " . pusBtnFlg . " `nButtonData: " . pusBtnData . " `nRawButton: " . pulRawBtn . " `nX: " . px . " `nY: " . py . " `nExtrainfo: " . pextraInfo . "`n" . info_text
      Tooltip %info_text%
      SetTimer, RemoveToolTip, 3000
      
   }
   else ifequal, nRC, 1   ; device is a keyboard
   {
      ; do nothing
   }
   else ifequal, nRC, 2    ; device is not a keyboard or mouse
   {
      ; do nothing
   }

   ; for testing only
   info_text_length := StrLen(info_text)
   If info_text_length > 500
      info_text_length = 500
   info_text := SubStr(info_text, 1 , info_text_length)

}


; automatically updates the script as soon as it is changed
UPDATEDSCRIPT:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%

      SplashTextOn,,,Updated Script,
      Sleep,500
      Reload
   }
Return

; for testing only
RemoveToolTip:
   SetTimer, RemoveToolTip, Off
   info_text := ""
   ToolTip
Return

; Win+C will exit the script
#c::
   Gosub cleanup
Return   

cleanup:
   DllCall("FreeLibrary", "UInt", hModule)  ; It is best to unload the DLL after using it (or before the script exits).
ExitApp


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 2nd, 2009, 4:21 pm 
Offline

Joined: September 25th, 2006, 7:13 pm
Posts: 6
Location: Peru
Hello Ucla and Hallo elmulti!
I've tried elmulti's script in my A4Tech WOP-35 Mouse on Windows XP (32 bit). The result is the same as Micha's AutoHotkeyRemoteControlDLL.ahk script:
FOREMOST WHEEL:
UPWARD: The message is:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 1024
ButtonData: 120
RawButton: 0
X: 0
y: 0
Extrainfo: 0

DOWNWARD: The message is:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 1024
ButtonData: 65416
RawButton: 0
X: 0
y: 0
Extrainfo: 0

REAR WHEEL:
UPWARD: The message is:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 1024
ButtonData: 240
RawButton: 0
X: 0
y: 0
Extrainfo: 0

DOWNWARD: The message is:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 1024
ButtonData: 65296
RawButton: 0
X: 0
y: 0
Extrainfo: 0

MIDDLE BUTTON:
PRESSED DOWN:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 16
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

RELEASED:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 32
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

LEFT BUTTON:
PRESSED DOWN:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 1
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

RELEASED:
Mouse-input
Devicenumber: 2
Flags: 0
BtnFlag: 2
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

RIGHT BUTTON:
PRESSED DOWN:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 4
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

RELEASED:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 8
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

4th BUTTON:
PRESSED DOWN:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 64
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

RELEASED:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 128
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

5th BUTTON:
PRESSED DOWN:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 256
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

RELEASED:
Mouse-input
Devicenumber: 4
Flags: 0
BtnFlag: 512
ButtonData: 0
RawButton: 0
X: 0
y: 0
Extrainfo: 0

AHK doesn't discriminate the wheels but can remap the buttons. V.g. to assign the letter "k" for the 3rd mousebutton:
Code:
Mbutton::k
I want to assign horizontal scrolling to foremost wheel (middle button), and vertical scrolling to rear wheel, according to that I posted on page 7. Can you or somebody please help me?
Thanks and best regards.

_________________
¿Cuándo traducimos AHK al español?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 2nd, 2009, 7:01 pm 
Offline

Joined: January 14th, 2008, 9:10 pm
Posts: 35
Location: Germany
Hi Cholito,
the ButtonData of the two wheels is different, so one can use them to differentiate between the wheels. I missed that in your previous post.

Try this script:
Code:
; based on code by Micha
; changed by elmulti
; this one is for mouse input only

#SingleInstance force
; path to AutohotkeyRemoteControl.dll
HomePath=AutohotkeyRemoteControl.dll
; load the dll
hModule := DllCall("LoadLibrary", "str", HomePath)  ; Avoids the need for DllCall() in
OnMessage(0x00FF, "InputMsg")
DetectHiddenWindows, on
OnExit, cleanup
SetTimer,UPDATEDSCRIPT,1000 ; for testing and developing

; register mouse
EditUsage = 2
EditUsagePage = 1
Gui, Show, Hide x0 y0 h0 w0, Autohotkey HID-Support
HWND := WinExist("Autohotkey HID-Support")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
   MsgBox RegisterDevice failed. Errorcode: %errorlevel%
   goto cleanup
}

Return

; deactivate normal wheel-action
$WheelUp::
$WheelDown::
   ; do nothing
Return


InputMsg(wParam, lParam, msg, hwnd)
{
   DeviceNr = -1
   ; get device number and type
   nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
   if (errorlevel <> 0) || (nRC == 0xFFFFFFFF)
   {
      MsgBox GetWM_INPUTHIDData failed. Errorcode: %errorlevel%
      goto cleanup
   }
 
   ifequal, nRC, 0   ; device is a mouse
   {
      ; process mouse data
      nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTMOUSEData", UINT, wParam, UINT, lParam, "UINT *" , pusFlags, "UINT *", pusBtnFlg
      , "UINT *" , pusBtnData, "UINT *", pulRawBtn, "UINT *" , px, "UINT *", py, "UINT *", pextraInfo, "Cdecl UInt")   
      if (errorlevel <> 0) || (nHandle == -1)
      {
         MsgBox GetWM_INPUTMOUSEData failed. Errorcode: %errorlevel%
         goto cleanup
      }
      
      DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl Int")
      DeviceNumber := DeviceNumber +1 ;Index 0
      
      if (DeviceNumber = 4)   ; This has to match your device number!
      {
         ; this function performs the different actions for different wheels
         MouseWheelActions(pusBtnFlg, pusBtnData)
      }
      
   }
   else ifequal, nRC, 1   ; device is a keyboard
   {
      ; do nothing
   }
   else ifequal, nRC, 2    ; device is not a keyboard or mouse
   {
      ; do nothing
   }

}

; customize this function to fit your needs!
MouseWheelActions(BtnFlg, BtnData)
{
   if (BtnFlg <> 1024)         ; abort if BtnFlg is not 1024
   Return
   
   if (BtnData = 120)         ; front wheel upwards
   {
      Gosub, Scroll_Left
   }
   else if (BtnData = 65416)   ; front wheel downwards
   {
      Gosub, Scroll_Right
   }
   else if (BtnData = 240)   ; rear wheel upwards
   {
      Send {WheelUp}
   }
   else if (BtnData = 65296)   ; rear wheel downwards
   {
      Send {WheelDown}
   }
}
      
Scroll_Left:
   ControlGetFocus, fcontrol, A
   Loop 2   ; <-- Increase this value to scroll faster.
   {
      SendMessage, 0x114, 0, 0, %fcontrol%, A  ; 0x114 is WM_HSCROLL and the 0 after it is SB_LINERIGHT.
   }
Return

Scroll_Right:
   ControlGetFocus, fcontrol, A
   Loop 2   ; <-- Increase this value to scroll faster.
   {
      SendMessage, 0x114, 1, 0, %fcontrol%, A  ; 0x114 is WM_HSCROLL and the 1 after it is SB_LINELEFT.
   }
Return


; automatically updates the script as soon as it is changed
UPDATEDSCRIPT:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%

      SplashTextOn,,,Updated Script,
      Sleep,500
      Reload
   }
Return


; Win+C will exit the script
#c::
   Gosub cleanup
Return   

cleanup:
   DllCall("FreeLibrary", "UInt", hModule)  ; It is best to unload the DLL after using it (or before the script exits).
ExitApp

It deactivates the normal scrolling function and then makes one wheel scroll vertical and the other horizontal.
If your device number is not 4, you need to adjust the script.

@Ucla: It should be no problem to change this to what you need. Just change the content of "MouseWheelActions".

Let me know if this works you you.
Happy New Year,
elmulti


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 1:32 am 
Offline

Joined: December 20th, 2007, 4:12 am
Posts: 22
elmulti wrote:
It deactivates the normal scrolling function and then makes one wheel scroll vertical and the other horizontal.
If your device number is not 4, you need to adjust the script.

@Ucla: It should be no problem to change this to what you need. Just change the content of "MouseWheelActions".

Let me know if this works you you.
Happy New Year,
elmulti


Does that mean you've found a way to deactivate normal function of keys too?

Thanks


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 8th, 2009, 9:00 am 
Hey, looks you have done a nice jod.... maybe you can help me out, im new with AutoHotkey, but what I want to do is to be able to remap my external USB HID Keyboard keys (but only remapping the external HID, without affecting the keys of the HID keyboard included in my laptop).

I have read the basics and followed some tutorials, but so far I can only remap keys but afecting both keyboards... Is there a way to only chose one keyboard to remap???

Hope you can help me out, since I tryied to understand your code, but it is too advanced for me...

Thanks in advance

John


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 152 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9, 10, 11  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: DataLife and 13 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