How to change what I've set a key to do in ahk - autohotkey

I'm trying to make a script for a game called Hearthstone. The script will be used to press a certain button and play a certain card. The only problem I have is that the cards change position based on how many you have. So I want to know how I could make buttons to choose the amount of cards in my hand.
I've come across the Hotkeys command but it seems to be more of a toggle thing. All the cards are bound from 1-10 and was thinking that I could make it so ^1-^10 represents how many cards I have but I don't know how I could do that.

Oleg's comment was more of my answer than I thought.
setting ^1 to ^1::numCards=1 and so on, I was able to set an if statement to do what I wanted something to do when the variable numCards equated to different things. Such as:
1:
if numCards = 1
{
do thing
}
return
and so on...

Related

I need to create a Script in Unity 3D that change the text when I click a key button (1,2,3,4), then the text change

Example: A NPC greet you, and you have multiple choises that are questions for the NPC and if you want to know one answer of this questions, you click one button (1,2,3,4). Then the text change and give you the answer of the question.
I'm going to assume you have already set up your GUI and NPC Script.
Getting when a key is pressed is pretty simple in Unity: Use UnityEngine.Input
Example of use:
if(Input.GetKeyDown(KeyCode.Alpha1)) {
//do something
}
This is a basic example.
Input.GetKeyDown returns true only when the key is pressed at that specific moment of checking (the frame). KeyCode.Alpha1 is the key for '1' at the top of alphanumeric keyboards.
To get when the key is held down, for jumping or running, use Input.GetKey instead. This will be true if the key is held down at that instance, instead of only one at the beginning.
To get when the key is released, use 'Input.GetKeyUp'. This only runs once the key is let go.
For setting the color of a Textbox, use yourTextBox.color. I believe it works with both legacy Textboxes and TextMeshPro.
The way to do what you have is this:
In the Update call, check if an NPC is talking with the player.
If so, then check if the player has pressed 1 ,2, 3, or 4, using Input.GetKeyDown. (To make it nicer looking, have each option in a list and use the index of the result. KeyCode is an enum, so you can save it like any other variable.)
Call some function that returns the response to the answer. Return a string or something.
Override the text in the Textbox with the answer, and use yourTextBox.color to set the color as you wish.
This should cover it. I may have some typos or errors, but the basic principals should work. Also, make sure you implement it in a way that makes it easier to edit later. You don't want to write code that can't be added on later, trust me...

New unity input system - is there a way to not execute an action if a modifier is being pressed?

So I want 2 different things to happen for when SHIFT+Q is pressed and when merely 'q' is pressed.
Currently when I press SHIFT+Q both actions are being fired, and I don't want that. Is there a way to do this elegantly in the action mapping? I would prefer not to have to hardcode keys in my scripts, but if that's the only way then I will just check in script if shift is currently engaged. It will be a giant headache in the future though if I want to allow players to edit key mappings.
For anyone coming across this in the future - It looks like this feature is being implemented in InputSystem 1.4.0+
(ChangeLog: https://github.com/Unity-Technologies/InputSystem/blob/develop/Packages/com.unity.inputsystem/CHANGELOG.md)
From the changelog:
Added support for keyboard shortcuts and mutually exclusive use of modifiers.
In short, this means that a "Shift+B" binding can now prevent a "B" binding from triggering.
Just need to pick one of the new 'OneModifierComposite' or 'TwoModifierComposite'.
Edit: please scroll to the bottom of this post. It turns out there’s actually a way to do this natively
I’m not totally sure, but one thing that I know will for sure work is to have separate actions mapped to shift and to q. Then in your OnShift function, simply set a “shiftIsPressed” flag to true or false, depending on whether the context is starting or ending. Then your your OnQ function can look something like this:
void OnQ(CallbackContext ctx)
{
if(!ctx.actionStarted) return;
if(shiftPressed) ShiftQ();
else Q();
}
This will keep key remapping open to you. It’s not perfect, if the player remaps Q to, say R, it will also remap ShiftQ to ShiftR. Without knowing more about your application though, that sounds like a good thing.
Edit:
To get Shift+Q to register as a separate action from Q, all you need to do is click the plus button on your ShiftQ action and select “Button With One Modifier Composite”. Then set Shift as the modifier and Q as the button. If you want to rebind Shift+Q to, say R, then set the button to R and the modifier to “Any Button”.
Hope this helps!

PyQt5 select text across multiple QTextEdit boxes

I am trying to create something similar to this in PyQt5:
https://www.screencast.com/t/1FikGosKbS
I tried using a separate QTextEdit widget for each bullet point and overriding the enter key to go to the next textbox, but I don't know how to make multiple QTextEdit widgets selectable (and able to copy paste) like in the example.
How can I allow the user to drag to select text across multiple QTextEdit boxes? Or is there a better approach to this?
I don't know this application is made from Qt or not,but I have an idea.
Parhaps you might have made the most part of this application... I can't know them from your question.I write my opinion on the premise that you don't know QText handling at all.
QTextEdit,QTextDocument,QTextCursor are used fully.
1.To understand block.
2.To use QTextBlockUserData(If you want.)
3.To use QGraphicsItem as nodes.
4.To go other page,we add a new QTextEdit on QStackedWidget or replace the QTextDocument of QTextEdit.
5.To make sub-nodes block,you can coordinate the indentation of blocks.
QTextBlock is a read-only data in a document.
You make QTextBlockUserData and set it to the block.
If you select multiple blocks you want to drag & drop , you use QTextCursor and movePosition methods with sequence.
The nodes of this application can not be QTextListFormat,because we cannot handle mouse click on the style.But you can insert empty-style QTextListFormat.
The truth of the nodes may be QGraphicsItem.
You can allocate it each the start position of blocks and the item can also have the block data.
It will difficult to take care of the connection between the nodes and the blocks.
In advance, you must set QGraphicsView & QGraphicsScene.
I insert many data on the container.
Which should we control with nodes or block?
My trial.
1.Nodes & Text
2.To the other page
3.Sub nodes & blocks
4.close sub nodes & blocks
My trial is incomplete,but it will be completed with endurance.
Logically,I think I can go step until the good point with these combinations.
But it will be diffcult...
These nodes are made from QGraphicsItem and allocated each Blocks.
You must calculate the position and recalculate during editing.
The mouse cursor image is deleted on these images.
It is outrange of screenshot.

Bokeh - How to use box tool without default selections?

I have built a bokeh app that allows users to select windows in data and run python code to find and label (with markers) extreme values within these limits. For ease of interaction, I use the box select tool for the range selection. My problem arises when repeating this process for subsequent cases. After markers are placed for the results, they are rendered invisible by setting alpha to zero and another case needs to be chosen. When the new select box includes previous markers, they become visible based on the selection. How do I override this default behavior? Can markers be made unselectable? or can I add code to the customJS to hide them after they are selected?
Thanks in advance for any help!
There are a few possible approaches. If you just want non-selected glyphs to "disappear" visually, you can set a policy to do that as described here:
http://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs
Basically, for bokeh.plotting, pass
nonselection_fill_alpha=0.0,
nonselection_line_alpha=0.0,
as arguments to your plot.circle call or whatever. Or if you are using the low level bokeh.models interface, something like:
renderer.nonselection_glyph = Circle(fill_alpha=0.0, line_alpha=0.0)
But be aware (I think you already are) that the invisible markers are still there, and still selectable if the user happens to draw a box over them with the selection tool.
If you truly want only a subset of the data to be visible and selectable after a selection, I'd say you want to replace the data in the column data source wholesale with the subset in your selection callback.

Unity/NGUI Updating List at runtime

I was wondering if someone could explain to me how I update a list at runtime in Unity?
For example I have a spell book, which has 3 spells in it, when I drag them to my action bar they get re-parented to it, what I'm trying to do is get a list of each child under the actionbar transform,
My problem is where to actually do something like this if I try something like below in the update, it adds whatever's there many times, which I can understand since update runs every frame..
list = actionbarui.GetComponent(UIGrid).GetChildList();
for(var i =0;i < list.size; i++)
{
buttonList.Add(list[i].gameObject);
}
If I add a callback to the buttons so that whenever they're drag and dropped it runs the above code and add thing's additively, as in, if you drag just one "spell" on it will loop through once, which is fine, but as soon as you add another it loops through three times, that is, it already has one it then adds the same one again PLUS the new button that's just been dragged on for a total of 3.
I've tried changing the code to
list = actionbarui.GetComponent(UIGrid).GetChildList();
for each(var child : Transform in list.GetEnumerator())
{
buttonList.Add(child.gameObject);
}
But this simple doesn't add anything, I am unsure how to go about keep the lists update as they are dragged off and on, could anyone please explain how this is achieved?
Please ignore the second "list" code, it's implementing "BetterLists" as apart of NGUI, so doesn't follow standard list methods.
Thank you for reading
If I add a callback to the buttons so that whenever they're drag and dropped it runs the above code and add thing's additively, as in, if you drag just one "spell" on it will loop through once, which is fine, but as soon as you add another it loops through three times, that is, it already has one it then adds the same one again PLUS the new button that's just been dragged on for a total of 3.
That is the expected result here. You are running through the list of children and adding them to your buttonlist, so first time there is only one item to add, then when you add another child there are two items to add, thus resulting in three items.
Either don't have a for loop and do:
buttonList.Add(the_GameObject_that_was_just_added_to_the_bar);
Or clear your buttonList before the for loop:
list = actionbarui.GetComponent(UIGrid).GetChildList();
buttonList.Clear();
for(var i =0;i < list.size; i++)
{
buttonList.Add(list[i].gameObject);
}
Alternatively to Dover8's response, you can first check if the buttonList already contains a reference to the child to be added. If it does, continue. Otherwise add the new child.
However, given the expense of doing the checks, and since you are already looping through the list already, I'd recommend that you follow his suggestion to clear the list before running the loop. It will probably give you the best performance out of these examples.
If there's a reason you can't or shouldn't clear the buttonList, and you still need to run through it, I'd recommend my suggestion. It really depends on which implementation works best for what you are trying to do. The point is that there are several ways to do this, and they have different performance profiles you need to consider.