It is currently Wed Jan 27, 2021 7:56 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Auto W pusher
PostPosted: Sat Jun 27, 2020 9:45 pm 
Offline
User
User

Joined: Fri Jul 15, 2016 8:55 pm
Posts: 41
I have been playing a game that does not have an auto run option, e.g. you have to keep the W key pressed, so I put together the following that uses global shortcuts to simulate holding down the W key. You press CTRL1/CTRL 2 to activate/deactivate. Not sure this is the best way to do this as I am no expert but it seems to work.

Code:
Global hot, vk.w
Declare Sendkey(*value)

Procedure RegisterSystemHotkey(ID.i, Key1.i, Key2.i)
   RegisterHotKey_(0,ID, Key1, Key2)
EndProcedure
Procedure UnregisterSystemHotkey(ID.i)
   UnregisterHotKey_(0,ID)
 EndProcedure
 
 Procedure SendKey(*value)
    keybd_event_(#VK_MENU,0,#KEYEVENTF_KEYUP,0) ; Release ALT key
    keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0) ; Release CONTROL key
    keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0) ; Release SHIFT key
    keybd_event_(#VK_LWIN,0,#KEYEVENTF_KEYUP,0) ; Release WINDOWS key
    VK=#VK_W
     If hot=1
         Repeat
          Delay (20):keybd_event_(VK, Scan, Extended, 0)
         ForEver
     EndIf
EndProcedure
 
 RegisterSystemHotkey(1,#MOD_CONTROL, $31) : RegisterSystemHotkey(2,#MOD_CONTROL, $32) ;CTRL 1 / CTRL + 2
 
 If OpenWindow(0, 0, 0, 200, 80, "W pusher", #PB_Window_MinimizeGadget | #PB_Window_Minimize | #PB_Window_BorderLess)
  hk1 = TextGadget(#PB_Any, 5, 5, 120, 30, "CTRL+1 Enable/Disable")
  hk2 = TextGadget(#PB_Any, 5, 25, 120, 30, "CTRL+2 Enable/Disable")
  hk3 = TextGadget(#PB_Any, 5, 45, 120, 30, "Status = Disabled")
 
   Repeat
     Event = WaitWindowEvent()
      Select Event
       Case #WM_HOTKEY
         If hot = 0
           hot = 1
           SetGadgetText(hk3,"Status = Enabled")
           MyThread = CreateThread(@SendKey(),1)
         Else
           hot = 0
           SetGadgetText(hk3,"Status = Disabled")
           KillThread(MyThread)
           Delay(20):keybd_event_(VK, Scan, #KEYEVENTF_KEYUP | Extended, 0)
         EndIf
     EndSelect
   Until Event = #PB_Event_CloseWindow
   If IsThread(MyThread):KillThread(MyThread):EndIf
   UnregisterSystemHotkey(1) : UnregisterSystemHotkey(2)
   Delay(20):keybd_event_(VK, Scan, #KEYEVENTF_KEYUP | Extended, 0)
 EndIf


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye