コード例 #1
0
ファイル: freekey.py プロジェクト: vveliev/freekey
def echo_keypresses():
    print 'Echoing key presses.'
    print 'Press ctrl+c to exit.'
    control_keys = ["Control_R", "Control_L",]
    control = [False]
    
    def handle_keydown(event):
        print 'Key-down:'
        print '\tkey:',event.Key
        print '\tkey id:',event.KeyID
        print '\tscan code:',event.ScanCode
        if event.Key in control_keys:
            control[0] = True
        elif control[0] and event.Key in ('C','c'):
            sys.exit()
    
    def handle_keyup(event):
        print 'Key-up:'
        print '\tkey:',event.Key
        print '\tkey id:',event.KeyID
        print '\tscan code:',event.ScanCode
        if event.Key in control_keys:
            control[0] = False
            
    hm = HookManager()
    hm.HookKeyboard()
    hm.KeyDown = handle_keydown
    hm.KeyUp = handle_keyup
    hm.start()
コード例 #2
0
def main():
    onKeyPress = Constructor()
    keyboard = HookManager()
    keyboard.KeyDown = onKeyPress
    keyboard.KeyUp = onKeyPress
    keyboard.HookKeyboard()
    keyboard.start()
コード例 #3
0
ファイル: freekey.py プロジェクト: vveliev/freekey
 def run(self):
     print 'Running...'
     hm = HookManager()
     hm.HookKeyboard()
     hm.KeyDown = self.handle_keydown
     hm.KeyUp = self.handle_keyup
     hm.start()
コード例 #4
0
ファイル: freekey.py プロジェクト: n0rad/freekey
def echo_keypresses():
    print('Echoing key presses.')
    print('Press ctrl+c to exit.')
    control_keys = ["Control_R", "Control_L",]
    control = [False]

    def handle_keydown(event):
        print('Key-down:')
        print('\tkey:', event.Key)
        print('\tkey id:', event.KeyID)
        print('\tscan code:', event.ScanCode)
        if event.Key in control_keys:
            control[0] = True
        elif control[0] and event.Key in ('C','c'):
            sys.exit()

    def handle_keyup(event):
        print('Key-up:')
        print('\tkey:', event.Key)
        print('\tkey id:', event.KeyID)
        print('\tscan code:', event.ScanCode)
        if event.Key in control_keys:
            control[0] = False

    hm = HookManager()
    hm.HookKeyboard()
    hm.KeyDown = handle_keydown
    hm.KeyUp = handle_keyup
    hm.start()
コード例 #5
0
ファイル: freekey.py プロジェクト: n0rad/freekey
 def run(self):
     print('Running...')
     hm = HookManager()
     hm.HookKeyboard()
     hm.KeyDown = self.handle_keydown
     hm.KeyUp = self.handle_keyup
     hm.start()
コード例 #6
0
def writeEvent( e, K, M ):
	global FILEH
	s = getTime( T_START )
	st=str(s)+" "+str(K)+" "+str(e.ScanCode)+" "+str(e.Ascii)+" "+str(e.Key)+"\n"
	FILEH.write(	st.encode("utf-8") )

def keyDown( e ):
	if STATE:
		writeEvent( e, K_D, " Pressing: " + str( e.ScanCode ) )
	
def keyUp( e ):
	if STATE:
		writeEvent( e, K_U, " Released: " + str( e.ScanCode ) )

HM.KeyDown	= keyDown
HM.KeyUp		= keyUp
HM.start()
app			= None

class Application( QWidget ):
	LINES		= getSampleText( "text.txt" )
	OLINES 	= []
	LINE		= 0						#Which line it is on
	FONT		= QFont("Courier New", 11)

	def __init__( self ):
		super( Application, self ).__init__()
		self.START	= QPushButton( "Start Logging" )
		self.START.setFont( self.FONT )
		self.QUIT		= QPushButton( "!!! EXIT APPLICATION !!!" )
コード例 #7
0
ファイル: pykeycombo.py プロジェクト: sobodash/pykeycombo
	# Actions for each key state
	if state == 0x3c:
		send_key("Escape")
	elif state == 0xe:
		send_key("F5")
	elif state == 0xd:
		send_key("F7")

# Send an emulated keypress to the current window of the X session
def send_key(emulated_key):
	window = display.get_input_focus()._data["focus"];
	
	# Generate the correct keycode
	keysym = Xlib.XK.string_to_keysym(emulated_key)
	keycode = display.keysym_to_keycode(keysym)
	
	# Send a fake keypress via xtest
	Xlib.ext.xtest.fake_input(display, Xlib.X.KeyPress, keycode)
	display.sync()
	time.sleep(0.5)
	Xlib.ext.xtest.fake_input(display, Xlib.X.KeyRelease, keycode)
	display.sync()

# Load the hook manager and snoop on all KeyUp and KeyDown events
hm = HookManager()
hm.HookKeyboard()
hm.KeyUp = handle_release
hm.KeyDown = handle_press
hm.start()

コード例 #8
0
ups = [
    Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8')) for f in sounds
    if "up.wav" in f
]
spacedowns = [
    Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8')) for f in sounds
    if "down_space.wav" in f
]
spaceups = [
    Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8')) for f in sounds
    if "up_space.wav" in f
]
returndowns = [
    Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8')) for f in sounds
    if "down_return.wav" in f
]
returnups = [
    Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8')) for f in sounds
    if "up_return.wav" in f
]

hm = HookManager()
hm.HookKeyboard()
hm.KeyDown = handle_event_down
hm.KeyUp = handle_event_up

try:
    hm.run()
except:
    print("\nClick clack! Bye!")
コード例 #9
0
ファイル: Monitor.py プロジェクト: Echocage/ActivityMonitor
config = configparser.ConfigParser({'main': '.*'})
config.read('config')
is_target = re.compile(config.get('main', 'regex_window_title'), re.IGNORECASE)

last_active = 0

def event_handler(event):
    global last_active
    now = time.time()
    if time.time() > last_active + datetime.timedelta(seconds=30).total_seconds():
        active_window = get_active_window()
        matches_regex = is_target.search(active_window)
        if matches_regex:
            last_active = time.time()
            with sqlite3.connect("ActivityRecords.db") as db:
                results = db.execute("UPDATE activity SET end = ? WHERE end > ?",
                                     (now, now - datetime.timedelta(minutes=5).total_seconds())).rowcount
                if not results:
                    db.execute('INSERT INTO activity VALUES (?,?)', (now, now))
                db.commit()


if __name__ == '__main__':
    hm = HookManager()
    hm.HookKeyboard()
    hm.HookMouse()
    hm.KeyDown = event_handler
    hm.MouseAllButtonsDown = event_handler
    hm.start()
コード例 #10
0
                file = window[fileStart:fileEnd]

    return {"file": file, "project": project}


def OnKeyPress(key):
    global last_keypress, wpm

    key_history[pointer] += 1
    last_keypress = int(time.time())

    wpm += 0.2


hook = HookManager()
hook.KeyDown = OnKeyPress
hook.HookKeyboard()
hook.start()


def avg_keys_per_second():
    return round(sum(key_history[0:arraylength]) / (arraylength / 4), 2)


RPC.connect()


def update_rpc():
    global curr_minute, last_wpm, wpm

    if (round(time.time() / 60) != curr_minute):