Jump to content

Keypad


anixon
 Share

Recommended Posts

I have no experience with scripting.

What I want to try and achieve is to be able to launch a program based on a numeric (up to six digits) assigned to the program and using the Keypad have the program start by inputing the number plus Enter. As an example I might like Notepad to be started by inputing 234567 or Word 6732.

Link to comment
Share on other sites

  • Moderators

I have no experience with scripting.

What I want to try and achieve is to be able to launch a program based on a numeric (up to six digits) assigned to the program and using the Keypad have the program start by inputing the number plus Enter. As an example I might like Notepad to be started by inputing 234567 or Word 6732.

In order to do what your asking, you'd have to have an autoit script running at all times in the back ground. What happens when your using Calculator or typing an email and hit the numbers 234567 plus enter?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

In order to do what your asking, you'd have to have an autoit script running at all times in the back ground. What happens when your using Calculator or typing an email and hit the numbers 234567 plus enter?

Thanks for your response. The computer is dedicated to run surveillance software and the remote wirless keypad is only ever going to be used to start and stop that software.

Link to comment
Share on other sites

Thanks for your response. The computer is dedicated to run surveillance software and the remote wirless keypad is only ever going to be used to start and stop that software.

HotKeySet("{Numpad1}""{NumPadEnter}", "Execute1")
HotKeySet("{Numpad2}""{NumPadEnter}", "Execute2")
HotKeySet("{Numpad3}""{NumPadEnter}", "Execute3")
HotKeySet("{Numpad4}""{NumPadEnter}", "Execute4")
HotKeySet("{Numpad5}""{NumPadEnter}", "Execute5")
HotKeySet("{Numpad6}""{NumPadEnter}", "Execute6")
HotKeySet("{Numpad7}""{NumPadEnter}", "Execute7")
HotKeySet("{Numpad8}""{NumPadEnter}", "Execute8")
HotKeySet("{Numpad9}""{NumPadEnter}", "Execute9")
HotKeySet("{Numpad0}""{NumPadEnter}", "Execute0")

While 1
    Sleep(3000)
WEnd

Func Execute1()
    Run("Notepad.exe")
EndFunc
Func Execute2()
    Run("Notepad.exe")
EndFunc
Func Execute3()
    Run("Notepad.exe")
EndFunc
Func Execute4()
    Run("Notepad.exe")
EndFunc
Func Execute5()
    Run("Notepad.exe")
EndFunc
Func Execute6()
    Run("Notepad.exe")
EndFunc
Func Execute7()
    Run("Notepad.exe")
EndFunc
Func Execute8()
    Run("Notepad.exe")
EndFunc
Func Execute9()
    Run("Notepad.exe")
EndFunc
Func Execute0()
    Run("Notepad.exe")
EndFunc

kinda basic, and you could shorten it if you wanted, but does something like this work?

Runs notepad by simultaneously pushing any of the Number pad keys and the number pad enter.

Link to comment
Share on other sites

This can't handle multiple buffers, but it's a start:

#include <array.au3>
#include <misc.au3>

$Buffer = CreateBuffer("31,32,33")

BufferWaitComplete($Buffer)

;   Buffer string example: (using _isPressed key hexes)
;       31,32,33
;   Would wait for 
;       1, 2, 3
; Returns a "buffer" array, to be passed to 
Func CreateBuffer($string)
    Local $Buffer
; Break the buffer into individual keys
    $Buffer = StringSplit ($string, ",")
    
    return $Buffer
EndFunc

Func BufferWaitComplete($buffer, $timeout = 3000)
    Local $Timer = 0
    
; Ignore the StringSplit counter at the beginning of the array
    For $i = 1 to UBound($buffer)-1
        While NOT _IsPressed($buffer[$i])
            Sleep(1)
            
            If $Timer > 0 Then
            ; start over if timer ran out
                If TimerDiff($Timer) > $timeout Then
                    $Timer = 0
                    $i = 1
                EndIf
            EndIf
        WEnd
        $Timer = TimerStart()
    Next
EndFunc
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

  • Moderators

This is how I see it working:

Global $nNumBuffer = ''
_HotKeySetNums()

While 1
    Sleep(0x7FFFFFFF)
WEnd

Func _HotKeySetNums()
    HotKeySet('{Numpad1}', '_HKBuffer')
    HotKeySet('{Numpad2}', '_HKBuffer')
    HotKeySet('{Numpad3}', '_HKBuffer')
    HotKeySet('{Numpad4}', '_HKBuffer')
    HotKeySet('{Numpad5}', '_HKBuffer')
    HotKeySet('{Numpad6}', '_HKBuffer')
    HotKeySet('{Numpad7}', '_HKBuffer')
    HotKeySet('{Numpad8}', '_HKBuffer')
    HotKeySet('{Numpad9}', '_HKBuffer')
    HotKeySet('{Numpad0}', '_HKBuffer')
    For $iCC = 0 To 9
        HotKeySet($iCC, '_HKBuffer')
    Next
    HotKeySet('{ENTER}', '_HKEnter')
    HotKeySet('{NUMPADENTER}', '_HKEnter')
EndFunc

Func _HKBuffer()
    $nNumBuffer &= Int(StringReplace(StringReplace(@HotKeyPressed, '{Numpad', ''), '}', ''))
EndFunc

Func _HKEnter()
    HotKeySet('{ENTER}')
    Send('{ENTER}')
    HotKeySet('{ENTER}', '_HKEnter')
    If $nNumBuffer = '' Then Return ''
    _ProgramsToRun($nNumBuffer)
    $nNumBuffer = ''
    Return ''
EndFunc

Func _ProgramsToRun($nNumProg)
    Switch $nNumBuffer
        Case 123
            Run('NotePad.exe')
        Case 1234
            Run('Calc.exe')
    EndSwitch
    Return ''
EndFunc

Edit:

Changed the Enter Function so it actually sends enter.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

This is how I see it working:

Global $nNumBuffer = ''
_HotKeySetNums()

While 1
    Sleep(0x7FFFFFFF)
WEnd

Func _HotKeySetNums()
    HotKeySet('{Numpad1}', '_HKBuffer')
    HotKeySet('{Numpad2}', '_HKBuffer')
    HotKeySet('{Numpad3}', '_HKBuffer')
    HotKeySet('{Numpad4}', '_HKBuffer')
    HotKeySet('{Numpad5}', '_HKBuffer')
    HotKeySet('{Numpad6}', '_HKBuffer')
    HotKeySet('{Numpad7}', '_HKBuffer')
    HotKeySet('{Numpad8}', '_HKBuffer')
    HotKeySet('{Numpad9}', '_HKBuffer')
    HotKeySet('{Numpad0}', '_HKBuffer')
    For $iCC = 0 To 9
        HotKeySet($iCC, '_HKBuffer')
    Next
    HotKeySet('{ENTER}', '_HKEnter')
    HotKeySet('{NUMPADENTER}', '_HKEnter')
EndFunc

Func _HKBuffer()
    $nNumBuffer &= Int(StringReplace(StringReplace(@HotKeyPressed, '{Numpad', ''), '}', ''))
EndFunc

Func _HKEnter()
    HotKeySet('{ENTER}')
    Send('{ENTER}')
    HotKeySet('{ENTER}', '_HKEnter')
    If $nNumBuffer = '' Then Return ''
    _ProgramsToRun($nNumBuffer)
    $nNumBuffer = ''
    Return ''
EndFunc

Func _ProgramsToRun($nNumProg)
    Switch $nNumBuffer
        Case 123
            Run('NotePad.exe')
        Case 1234
            Run('Calc.exe')
    EndSwitch
    Return ''
EndFunc

Edit:

Changed the Enter Function so it actually sends enter.

Take a bow this solution works just fantastic what can I say YOU ARE A LEGEND and clearly a code cutter of exceptional talent
Link to comment
Share on other sites

Take a bow this solution works just fantastic what can I say YOU ARE A LEGEND and clearly a code cutter of exceptional talent

I have modified the script to pop a message on start as well as adding a beep to two of the Cases and adding a Case 99 as a means to exit from the routine. The code now looks like this

; Start Security Surveillance

MsgBox(0, "VISEC", "To Start Keypad Monitor [Enter] or [99] to Terminate")

Global $nNumBuffer = ''

ETC ETC

I haved added to the following routine

Func _ProgramsToRun($nNumProg)

Switch $nNumBuffer

Case 1234

Beep(500, 1000)

Run('c:\program files\visec\visec.exe /auto')

Case 123

Beep(500, 1000)

Run("taskkill.exe /f /im visec.exe")

Case 99

Exit 0

EndSwitch

Return ''

EndFunc

The only problem is if a Desktop Icon is selected (single click to say then look at the properties) and you then Exit the routine by inputing 99 [Enter] then the program which is selected and highlighted on the desktop will launch. If no icon is selected and highlighted then nothing happens.

Link to comment
Share on other sites

  • Moderators

That's funny... I modded my earlier one to let the "Enter" key pass through, as I he said he didn't need the numbers ... I can't imagine him not needing to be able to use "Enter".

Enter has no effect, unless he actually used a key set of numbers.

But the time mod was a great idea ;)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi those who have contributed to providing me with a solution I very much appreciate the help and I can report that it works really well (terrific in fact). I am going to purchase a USB Light and mod the script to switch it on and off as part of launching and closing the surveillance software. So together with the beep mod I will have both audio and visual feedback that the system has been activated/de activated. Best Wishes to you all and thank you again Anthony in Australia

Link to comment
Share on other sites

Thanks, I was expecting to get no acknowledgment at all in here. I appreciate it ;)

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

  • Moderators

Thanks, I was expecting to get no acknowledgment at all in here. I appreciate it ;)

You're not distastefully arrogant enough to "not" get acknowledgement. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...