I need to write a program that runs in the background without a gui window or a console window. It also needs to recognize when a key is pressed. Is there any way to do that? And if yes, then how?

Any and all suggestions would be great. thanks.

I need to write a program that runs in the background without a gui window or a console window. It also needs to recognize when a key is pressed. Is there any way to do that? And if yes, then how?

Any and all suggestions would be great. thanks.

yeah re-write your device driver

I need to write a program that runs in the background without a gui window or a console window. It also needs to recognize when a key is pressed. Is there any way to do that? And if yes, then how?

Any and all suggestions would be great. thanks.

Could you explain your problem with some more detail? what key pressed and recognize?

I need to write a program that will run a command when a certain key is pressed. For example:

Do you mean a TSR program(termiate stay resident)

I need to write a program that will run a command when a certain key is pressed. For example:

I just found this thread for capturing key-press on Windows machine. This might help you.

kath.

I think hes talking like a key logger. He probably wants to make it so that when a key is pressed it sends what key to his email or something. There can be honorable and dishonorable uses for this. It can be used if he is a parent to make sure his kids dont look at porn, or it can be used to steal information.... which 1 is it?

Thanks... I figured it out... i just need this program to recognize when a scanner is used by identifying certain keys being used. im going to use a hook just like you would in a keylogger... thanks for the help everyone.

Post your code, I would like to see how you did this.

Here it is... hope this helps

import pythoncom, pyHook


'''
I used identifying characters on the magnetic swipe card
to recognize when the device was used. (the 'shift' key and the '%' key)

After those keys have been pressed in order, the keys are added to a list.

Once the list reached a certain length, I stopped adding to the list
and executed a command.

A timer could be used instead of the length of the list to decide when
to execute the command if desired.
'''


def OnKeyboardEvent(event):
    hm.pressed_keys_list.append(str(event.Ascii))


    print len(hm.pressed_keys_list)

    # makes sure the first character is the shift key to start the list
    # if not, the list resets

    if hm.pressed_keys_list[0] == '0':

          # When the list has 2 string in it, check to make sure the second
          # one is the "%" key.  If not, reset the list.
          if (len(hm.pressed_keys_list) >= 2):
              if hm.pressed_keys_list[1] == '37':
                  
                  hm.valid_list = 1
                  
              else: hm.pressed_keys_list = []
                  
              
    else:
      hm.pressed_keys_list = []



    # if a valid list exists, see if the list is longer than 18 characters      
    if hm.valid_list:
        if len(hm.pressed_keys_list) > 18:
            # preform action

            #action()


            # restet list

            hm.pressed_keys_list = []
            

      
          
          

  
  
### main ###

# create a hook manager

hm = pyHook.HookManager()

hm.pressed_keys_list = []
hm.valid_list = 0
# watch for all keyboard events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.