Jump to content

Detect any pressed key and last clicked GUI button


Jefrey
 Share

Recommended Posts

Hi guys

 

I own a basic Samsung notebook that does not have a num pad (not even integrated in alpha keys. It really brings nothing to use as num pad). And it's weekend, Independence Day (I'm from Brasil) and tomorrow's gonna be holiday in my city, so I can't buy a $12 USB numpad right now. I wanna run an application that requires exclusively some numpad keys.

I started Googling about it, and I even found a project that adds a film over the touchpad, a 12 MB software installed and, after a hotkey, the touchpad starts working as numpad. A little crazy, I think (it's just a concept). I didn't know even that the touchpad allows the software to know what area has been touched (does it?). Anyway, this project is called Number Pad Film.

After more unsuccessful searches, I had an idea to make something similar to it, but using the own keyboard. The user will assign hotkeys to every numpad key, so when the user presses that hotkey, the assigned key will be sent using Send() function normally ({NUMPAD0} - {NUMPAD9}). I didn't find anything about it, but if i'm recreating the wheel, please tell me. I will code a basic app that  will just show a GUI up with a numpad made with buttons. The user will click a button and it will ask for the hotkey that the user wants to assign to that virtual key. Example: in the GUI, the user clicks "7", then something like "What hotkey do you want to assign to that key?" will be show, and the user must type the hotkey he wants. It's something like assigning a hotkey to some desktop shortcut: you don't actually write it. You press the hotkey and it detects.

Furthermore, to make the code cleaner, I'd like to assign only one function for the "onclick event" of all the numpad buttons on the GUI. For example, I have all the 1-9 buttons on the GUI, but all those buttons will call just one function, for example, "myClickFunction". This function must detect which was the last button clicked, to get its label. Is there a way?

If not possible, I guess the best option is using >SetOnEventA, but the way I explained above would be faster and cleaner.

Just to have an idea on what I wanna do:

#RequireAdmin
#include 'onEventFunc.au3'

SetOnEventA("^j", "numpadnum", $ParamByVal, "1")
SetOnEventA("^k", "numpadnum", $ParamByVal, "2")
SetOnEventA("^l", "numpadnum", $ParamByVal, "3")
SetOnEventA("^u", "numpadnum", $ParamByVal, "4")
SetOnEventA("^i", "numpadnum", $ParamByVal, "5")
SetOnEventA("^o", "numpadnum", $ParamByVal, "6")
SetOnEventA("^7", "numpadnum", $ParamByVal, "7")
SetOnEventA("^8", "numpadnum", $ParamByVal, "8")
SetOnEventA("^9", "numpadnum", $ParamByVal, "9")

Func numpadnum($num)
   Send("{NUMPAD" & $num & "}")
EndFunc

While True
   Sleep(100)
WEnd

Thanks in advance!

Edited by Jefrey

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

What about a simple HotKeySet with a @HotKeyPressed macro?

That's quite easy to do, however be careful please. Mods will probably lock your thread, since any kind of relation to a game is strictly forbidden.

( well, even if I disagree with this highly strict rule, we're part of this forum, we must accept the rules :) )

Link to comment
Share on other sites

  • Moderators

Jefrey,

Unc3nZureD makes a good point - but as your problem is essentially one of key mapping I am prepared to let it run. However I suggest amending the end of your first paragraph and being more careful in future. ;)

Unc3nZureD,

well, even if I disagree with this highly strict rule, we're part of this forum, we must accept the rules

Quite correct - so why bother mentioning your personal feelings? We are not going to change the rules just for you. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks, I didn't know about this rule about games... Just for a matter of curiosity... why is that not allowed?  :blink:

I tried writing carefully since I know detecting keystrokes is what some guys want, to create keyloggers. But my goal is to create something like this:

shortcut.jpg

Note the "Shortcut key" field: the user must click it and press the hotkey he wants to assign to the shortcut (Microsoft Word, in this picture). So the user can choose any hotkey to assign to the virtual numpad keys.

So I found the >HotKeyInput UDF. But it requires >HotKey UDF which doesn't support arguments. I'd like to use it with SetOnEventA, so I wouldn't have to repeat many functions. But it's a simple app with just a few keys, so that's not a problem right now. I couldn't find a way to convert the HotKeyInput hexcodes into Send()-like strings, like "!c" or "^c". If there's some way, please tell me  :D

Thank you guys!

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

  • Moderators

Jefrey,

 

why is that not allowed?

It was discussed (for the umpteenth time) just a few weeks ago in this thread - although there are one or two small detours along the way. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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