ahk click down mouse button while holding down a key on keyboard - keyboard

I want to move the mouse with one hand while with the other making the button clicks with the keyboard.
The difficult part was to instruct AutoHotKey to hold down the mouse button while holding down the key on the keyboard. So you be able to click and drag.
It makes the clicks with the 1, 2 and 3 keys at the keyboard, in inverse order (left click with the 3, as preserving left click with the index finger but of the other hand, trying to mirror the workings inside the brains hemisphere, or something)
This script is activated while ScrollLock is ON (finally some good use for that beautiful and neglected key, activating all sorts of keyboard shortcuts for AutoHotKey)

#NoTrayIcon
if (GetKeyState("ScrollLock", "T")) ; check state for icon
{
Menu, Tray, Icon
return
}
else
{
Menu, Tray, NoIcon
return
}
ScrollLock:: ; From state 0 to state 1 (Activated)
Send, {ScrollLock}
Menu, Tray, Icon
SoundBeep, 261.43, 150 ; low tone
SoundBeep, 329.63, 150 ; hight tone
return
#If GetKeyState("ScrollLock", "T") ; State 1 (Activated)
3::
While GetKeyState("3", "P")
{
Click, Left, Down
KeyWait 3
Click, Left, Up
}
Return
2::
While GetKeyState("2", "P")
{
Click, Middle, Down
KeyWait 2
Click, Middle, Up
}
Return
1::
While GetKeyState("1", "P")
{
Click, Right, Down
KeyWait 1
Click, Right, Up
}
Return
ScrollLock:: ; From State 1 to State 0 (Deactivated)
Send, {ScrollLock}
Menu, Tray, NoIcon
SoundBeep, 329.63, 150 ; hight tone
SoundBeep, 261.43, 150 ; low tone
return
^SPACE:: ; Always on Top Functionality
Winset, Alwaysontop, , A
return
#If
Script: Keyboard-Clicks.ahk
It gets activated with the ScrollLock key.
It shows the a tray icon when activated.
It hides the icon when is deactivate it with ScrollLock key again.
Key combination Ctrl+Space for AlwaysOnTop the currently active window.
It makes a distinctive sound beep for activated and de-activated state.
Compiled with an icon from Font Awesome of a hand.
Font-Awesome-left-hand-paper Icon PNG with Transparency
https://i.imgur.com/6tvfVNS.png

Related

How to detect a button click and a normal click in bevy

I'm making a tower defense game in bevy and I'm having problems with placing a tower. So basically I want to make it so that when you click one of the buttons (each one spawns a different tower) an asset/sprite of the tower should follow your mouse and when the mouse is clicked AGAIN it should spawn the tower.
Currently my program registers the button click, but it goes into 2 ifs so when the button is clicked it automatically spawns a tower somewhere (not even below the button) without waiting for the user to click again. So the Interaction::Clicked only checks if the button was clicked, but doesn't grab the mouse click event, it only reads it so therefore if the mouse is clicked for a longer period of time (human click) the code will go into the second if and spawn the tower (I don't know why it spawns it where it is on the picture below). How can I fix this? Picture:
Towers spawning in some random place. First button spawns them at around (200, 0, 0)
Code:
fn tower_button_interaction(
mut commands: Commands,
windows: Res<Windows>,
mouse: Res<Input<MouseButton>>,
assets: Res<GameAssets>,
interaction: Query<(&Interaction, &TowerType), Changed<Interaction>>
) {
let window = windows.get_primary().unwrap();
for (interaction, tower_type) in &interaction {
match interaction {
Interaction::Clicked => {
info!("Spawning: {tower_type} wizard");
// Upon clicking the mouse, spawn the selected tower on the map
if mouse.just_pressed(MouseButton::Left) {
if let Some(position) = window.cursor_position() {
spawn_tower(&mut commands, *tower_type, &assets, position.extend(0.));
}
}
}
Interaction::Hovered => {}
Interaction::None => {}
}
}
}
I also tried changing the if mouse.just_pressed(MouseButton::Left) to if matches!(interaction, Interaction::Clicked), but the same thing happened.

How to see if mouse is down or screen is touched in event?

I see that I can use event.is_pressed() to check for when a click (and I'm assuming, a tap) has occurred. But any additional motion while the LMB (left mouse button) is still down, doesn't equal true using is_pressed()
Here's a block of code I'm using for this test:
func _input(event):
var tilemap = find_node("TileMap")
if(event.is_pressed()):
tiles.highlight(event.position)
When I actually click, tiles.highlight() is called, but while I move the mouse with LMB still down, it doesn't call tiles.highlight(). Is there a different function I need to use here?
You can use polling to see if the mouse button is being held down.
func _ready():
set_process(true)
func _process(delta):
if Input.is_mouse_button_pressed(1): # Left mouse button.
print('Left mouse button pressed. ', get_viewport().get_mouse_position())
Otherwise, you can set a variable, for example mouse_button_pressed, to true or false in the _input function when a mouse button is pressed or released and then check it in the _process function:
func _input(event):
if event is InputEventMouseButton:
if event.is_pressed(): # Mouse button down.
mouse_button_pressed = true
elif not event.is_pressed(): # Mouse button released.
mouse_button_pressed = false
func _process(delta):
if mouse_button_pressed:
print('Left mouse button pressed. ', get_viewport().get_mouse_position())

how to check if you cklicked (with your mouse) in an defined area in python/pygame

I want to check if you clicked in an defined area, for example an area from 0,0 to 400,40 (pixel coordinates). I have this:
x = 0
y = 0
(mouse_posx, mouse_posy) = pygame.mouse.get_pos()
press = pygame.key.get_pressed()
if mouse_posx > x and mouse_posx < x+400 and mouse_posy > y and mouse_posy < y+40 and press != 0:
function()
I get no error but it does nothing.
Can someone tell me what i am doing wrong?
What you want to do is have your program listen for events. Once the event of mouse button is triggered, then record the mouse position. Then verify if the mouse position is inside the box.
Pygame mouse
Oh and also, I dont think the event of mouse button gets recorded in the > pygame.keys.get_pressed <. I believe the pygame.keys.get_pressed is just for the keyboard.
I may be wrong, im using my mobile and dont have a computer with me.

Is there a way to get the cursor position in a mfc application?

I'm using the OnKeyDown handler to detect for an Enter key press:
void CShortestPathFinderView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if( nChar == VK_RETURN) //Enter key is pressed
{
CClientDC aDC(this);
rubberbanding = 0;
m_pTempElement->vertices[i++]= /*cursor position??*/;
mSecondPoint=m_pTempElement->vertices[0];
m_pTempElement->Draw(&aDC);
}
In the 3rd line of the if statement I need to store the cursor position in an array, but how do I acquire that point? Does the handler provide me with it? or is there a separate function to do so?
To get the current cursor position, you can call GetCursorPos. I don't believe MFC provides a wrapper for this, so it'll just be the Win32 ::GetCursorPos. It returns the point in screen coordinates, so you'll (almost certainly) want to use ScreenToClient to convert that to client area coordinates before storing it.
Note, however, that GetCursorPos will return the position of the cursor when you call it. That may or may not be quite the same as the position the cursor was at when the key was pressed (though it will normally be at least quite close).
Usually, to add a cursor position like this, you'd want to react to the user clicking the mouse button (e.g., WM_LBUTTONDOWN). That message will tell you the position of the mouse when the button was clicked.

How to exit program with close button in XCB

Can not find any reference on how to close application by the "X" button. I'm programming using XCB and want to close the program by the "X" button. I looked and can't find anything about it. I know how to close by pressing a button. Also, by pressing the "X" button the window looks like it closes but doesn't.
I struggled on this topic some time ago as well.
Look at http://marc.info/?l=freedesktop-xcb&m=129381953404497 .
The key is to store the cookie for the WM_DELETE_WINDOW in a separate cookie...
xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(c, 0, 16, "WM_DELETE_WINDOW");
xcb_intern_atom_reply_t* reply2 = xcb_intern_atom_reply(c, cookie2, 0);
and in the event loop compare the client_message with the cookie2
case XCB_CLIENT_MESSAGE:
{
if((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply2).atom) ...
}

Resources