Sign in to follow this  
Followers 0
Baritonomarchetto

_IsPressed and HotKeySet

13 posts in this topic

Hi,

toying with "button pressing" I run into the different handling of inputs of this 2 functions: "IsPressed" rely on Hex values, "HotKeySet", instead, on "actual" keys (with some known ecception). This makes, i.e., difficult to set a variable in a .ini file and use it with both the functions.

Is there a solution to this?

Thanks

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Surely helps, thanks :D

but what about the use of lowercase letters? Why capital letters are used (in hex format) in _IsPressed and not lowercase? Just asking because with "Send" and "HotKeySet" is better to use lowercase ...

EDIT: Hmm, I had no success trying to use both _IsPressed and HotKeySet with the same variable, even converting string to hex (_StringToHex). Any solution to this?

Thanks

Edited by Baritonomarchetto

Share this post


Link to post
Share on other sites

If you post an example script, we could be more helpful. I don't know exactly what your problem is.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Let me explain: the function "IsPressed" accepts only a little (predefinite?) group of hex values. You can notice that letters are uppercase. While dealing with Send or HotKeyset, instead, it's generally good rule to use lower case letters. Than, if i define a variable and its hex

Local $var = i ;just an example: "i" could be a value loaded from an ini file
Local $hexvar = _StringToHex($var)

it's not handled correctly by IsPressed because it's not recognized

HotKeySet("$var", "myfunction")
...
...
myfunction()
...
If _IsPressed($hexvar, $hDLL) Then
...
...

Tell me if i was not clear (veeery probable :D )

Edited by Baritonomarchetto

Share this post


Link to post
Share on other sites

Baritonomarchetto,

Why are you using HotKeySet and _IsPressed on the same key in the same script? Why not just use one or the other? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

If caps/uppercase is the problem, you can use StringLower or StringUpper to give a consistent upper or lowercase value.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

_IsPressed will only accept the hex value of the uppercase letter, in other words, if your ini file has "i" in it, use StringUpper("i") to make it uppercase. Also, do not put the variable $var in quotes inside the hotkeyset, because it's not going to work that way.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Baritonomarchetto,

Why are you using HotKeySet and _IsPressed on the same key in the same script? Why not just use one or the other? :D

M23

I wrote a little script that uses _IsPressed, but i am not able to avoid that the key that trigger the script is sent. With HotKeySet the "key" is completely "hidden"... not sent

Share this post


Link to post
Share on other sites

Baritonomarchetto,

Could you let us see an example of this "little script", because I am having trouble understanding what you mean. From your explanation above it sounds as if using only one of the two (HotKeySet) is exactly what you need. So why the two together? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

_IsPressed will only accept the hex value of the uppercase letter, in other words, if your ini file has "i" in it, use StringUpper("i") to make it uppercase. Also, do not put the variable $var in quotes inside the hotkeyset, because it's not going to work that way.

Thanks: i wrote those strings by heart, so it's very likely that contain errors :D

Could it be a solution to write something like:

Local $var = i 
Local $hexvar = _StringToHex(StringUpper($var))

Will the pressure of lowercase "i" on the keyboard ("captured" by HotKeySet) be seen by also by _IsPressed when uppercased?

Share this post


Link to post
Share on other sites

Sure: i will show you something tomorrow (i have it in another PC and diggin it up to my mind is difficult for a newbie like me :D )

Baritonomarchetto,

Could you let us see an example of this "little script", because I am having trouble understanding what you mean. From your explanation above it sounds as if using only one of the two (HotKeySet) is exactly what you need. So why the two together? :huh:

M23

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Ok, here we are: take a look at this (reduced) script please

#include <Misc.au3>

Local $hDLL = DllOpen("user32.dll")

Local $keypressed = IniRead(".prog.ini", "key_assign", "key", 41) ;"A" in hex format
Local $otherkey = IniRead(".prog.ini", "otherkey_assign", "otherkey", "i") ; "i" in dec format

While 1
If WinActive("[CLASS:XLMAIN]") Then
bpress()
EndIf
Sleep(50)
WEnd

func bpress()
If _IsPressed($keypressed, $hDLL) Then
Send($otherkey)
While _IsPressed($keypressed, $hDLL)
         Sleep(5)
WEnd
EndIf
EndFunc

DllClose($hDLL)

This allows you to send a "i" when "a" key is pressed. The problem is that also "a" is sent then you will write "ai". Notice also on the iniread that the format of the button pressed is hex ("_IsPressed" function deals with this) and the format of the "other key" is dec (to deal with send function).

To obtain a sort of uniformation of formats for the key pressed and the other key sent, i thought to start dealing with HotKeySet. This solves the problem of the "ai" sending instaed of only "i" and uses dec format for keys BUT doesn't allow you to use i.e. parts like

While _IsPressed($keypressed, $hDLL)
         Sleep(5)
WEnd

wich is usefull if you wanna stop a ciclying.

Writing something like:

While HotKeySet($keypresed)
         Sleep(5)
WEnd

doesn't stop the key being sent if the button is kept pressed

This is essentially why i want to use both the functions ...

So the questions are:

1) how can modify the script to avoid the send of the key (i.e. "a") that pressed triggers the "otherkey" (i.e. "i")?

2) Couldn't the formats be uniformed (dec hex) with some trick or, eventually, lower case letters be introduced in _IsPressed ?

Thanks for the support :D

Edited by Baritonomarchetto

Share this post


Link to post
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
Sign in to follow this  
Followers 0