Jump to content

Get Keystroke / Key scancode?


mozart90
 Share

Recommended Posts

Hi,

I've bought a USB foot pedal - it is recognized as a HID Interface and seems to send a keystroke - but I do not know which.

(In an editor no chars ar written - and MS Word doesn't recognoze a valdid hotkey combination) but on the other hand some programs ( Total commander) seem to react on the foot pedal.

So how can i figure out the key scan code of this USB foot pedal device - because i like to map it on another key eg "space key" or something like that.

I suggest the keystroke it is "alt + arrow left", but wiht this code it doesn't work :-(

HotKeySet("!{left}", "keysend")
HotKeySet("{esc}", "end")

While 1    
WEnd    

func keysend()
    send("{space}")
EndFunc

func end() 
    exit(0)
EndFunc

Thanks

Mozart90

PS recording a macro and pressing the foot pedal doesn't record anything

Edited by mozart90
Link to comment
Share on other sites

Hi,

I've bought a USB foot pedal - it is recognized as a HID Interface and seems to send a keystroke - but I do not know which.

(In an editor no chars ar written - and MS Word doesn't recognoze a valdid hotkey combination) but on the other hand some programs ( Total commander) seem to react on the foot pedal.

So how can i figure out the key scan code of this USB foot pedal device - because i like to map it on another key eg "space key" or something like that.

I suggest the keystroke it is "alt + arrow left", but wiht this code it doesn't work :-(

HotKeySet("!{left}", "keysend")
HotKeySet("{esc}", "end")

While 1    
WEnd    

func keysend()
    send("{space}")
EndFunc

func end() 
    exit(0)
EndFunc

Thanks

Mozart90

PS recording a macro and pressing the foot pedal doesn't record anything

I don't know much about HID's but if you didn't need to install a special driver then it is likely that the footpedal behaves like a keyboard, as you think, or as a mouse so it could just simulate a mouse button.

This will show which keys it sends if it does send a key or a mouse button.

#include <misc.au3>
While 1
    $keys = ''
    For $n = 1 To 254
        If _IsPressed(Hex($n, 2)) Then
            $keys &= "0x" & Hex($n, 2) & ', '
        EndIf
    Next
    ToolTip($keys, 0, 0)
    If StringInStr($keys, "0x1B") Then
        Sleep(2000)
        Exit
    EndIf
    Sleep(50)
WEnd
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I don't know much about HID's but if you didn't need to install a special driver then it is likely that the footpedal behaves like a keyboard, as you think, or as a mouse so it could just simulate a mouse button.

This will show which keys it sends if it does send a key or a mouse button.

#include <misc.au3>
While 1
    $keys = ''
    For $n = 1 To 254
        If _IsPressed(Hex($n, 2)) Then
            $keys &= "0x" & Hex($n, 2) & ', '
        EndIf
    Next
    ToolTip($keys, 0, 0)
    If StringInStr($keys, "0x1B") Then
        Sleep(2000)
        Exit
    EndIf
    Sleep(50)
WEnd

thanks, the code works!

it's 0x05 :-)

I 'll write a small script which let me start or stop playback/record/ punch in with my footswitch while playing my instrument

I think this will be very comfortable :-)

include <misc.au3>
Opt ("WinTitleMatchMode",1)
HotKeySet("{esc}", "quit")

While 1
    If _IsPressed(Hex(05)) Then ; 
        if ProcessExists( ) then 
                send( {}) 

...
Wend

But could you explain the "for $n=1 to 254" loop while gettig the scan code?

And is there an easier way to exit?

Thanks mozart90

Link to comment
Share on other sites

thanks, the code works!

it's 0x05 :-)

That was lucky!

But could you explain the "for $n=1 to 254" loop while gettig the scan code?

Have a look at _IsPressed in the help. The loop just checks possible codes from 1 to 255 ie 1 to FF

And is there an easier way to exit?

I made it so that if you press Esc it will exit, but you can make it whatever. You could have a hot key call a function which simply exits. But since the script has served its use theres not much point in developing I would have thought.

Thanks mozart90

That's ok :)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...